2017-03-17 145 views
-1

但是,我正在實現自己的工具欄/操作欄,狀態欄顏色變爲棕色,並且我試圖給它一個深藍色的默認值。我該如何改變這一點。我試圖玩弄style.xml主題,也是工具欄主題。但我不明白。任何幫助讚賞。 styles.xml自定義工具欄更改狀態欄的顏色

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="colorAccent">@color/colorAccent</item> 
    </style> 

</resources> 

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/my_toolbar" 
    android:popupTheme="@style/ThemeOverlay.AppCompat" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@color/colorPrimary" 
    android:elevation="4dp" 
    android:paddingBottom="5dp" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    tools:context="com.example.com.mytoolbar.MainActivity" /> 

menu.xml文件

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <!-- "Mark Favorite", should appear as action button if possible --> 
    <item 
     android:id="@+id/refresh" 
     android:icon="@drawable/ic_refresh_black_48dp" 
     android:title="@string/refresh" 
     app:showAsAction="ifRoom"/> 

    <!-- Settings, should always be in the overflow --> 
    <item android:id="@+id/settings" 
     android:title="@string/settings" 
     app:showAsAction="never"/> 

</menu> 

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    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:orientation="vertical" 
    tools:context="com.example.com.mytoolbar.MainActivity"> 

    <include layout="@layout/toolbar" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

</LinearLayout> 
+1

嘗試從toolbar.xml中刪除popupTheme –

回答

0

使用以下工具欄的代碼:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/my_toolbar" 
    android:popupTheme="@style/ThemeOverlay.AppCompat" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary"    <!-- Check this line --> 
    android:theme="@style/MyToolbarStyle"     <!-- Custom theme added --> 
    android:elevation="4dp" 
    android:paddingBottom="5dp" 
    tools:context="com.example.com.mytoolbar.MainActivity" /> 

刪除android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

如果使用android:background="?attr/colorPrimary"工具欄會從基礎應用主題得到默認colorPrimary

於更改文本和溢流圖標的顏色,添加這個自定義主題style.xml並應用到工具欄:

<style name="MyToolbarStyle" parent="Widget.AppCompat.Light.ActionBar"> 
    <item name="android:textColor">@android:color/white</item> 
    <item name="android:textColorPrimary">@android:color/white</item> 
    <item name="android:textColorSecondary">@android:color/white</item> 
</style> 

希望這有助於。

+0

ok,但現在我的文本和溢出圖標變成黑色。我如何將它們更改爲主題默認值..白色!感謝您的幫助 – miatech

+0

請檢查我的更新答案。 – tahsinRupam

+0

很好..全白主題!偉大的 – miatech