2016-01-22 71 views
1

我正嘗試創建一個類似於OnePlus設備上的OxygenOS的黑暗主題。黑暗主題android應用程序

enter image description here

我改變了窗口背景爲黑色,但問題是在操作欄沒有變成純黑​​色。

<style name="DarkTheme" parent="Theme.AppCompact"> 
    <item name="android:colorPrimary">@color/black</item> 
    <item name="android:colorPrimaryDark">@color/black</item> 
    <item name="android:textColorPrimary">@color/white</item> 
    <item name="android:colorAccent">@color/white</item> 
    <item name="android:color">@color/white</item> 
    <item name="android:windowBackground">@color/black</item> 
    <item name="android:navigationBarColor">@color/black</item> 
    <item name="android:actionBarStyle">@color/black</item> 
</style> 

回答

3

在colors.xml替換這些值

<color name="colorPrimary">#101010</color> 
<color name="colorPrimaryDark">#000000</color> 

這將是足以改變工具欄的顏色。


如果你不想改變整個應用程序,主要顏色(這似乎是你試圖在第一個地方做),試圖通過創建一個新的工具欄:

添加這個應用程式的的build.gradle

compile 'com.android.support:design:23.1.1' 

添加到您的主要佈局(activity_main.xml中)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="mx.evin.apps.startingtemplate.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/a_main_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@android:color/black" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

    </android.support.design.widget.AppBarLayout> 

</android.support.design.widget.CoordinatorLayout> 

設置這在您的樣式(styles.xml):

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

並設置新的工具欄(MainActivity.java)。

Toolbar toolbar = (Toolbar) findViewById(R.id.a_main_toolbar); 
setSupportActionBar(toolbar); 
+2

thnx男人這兩種技術的工作! –