2015-06-07 35 views
0

我所要做的就是讓操作欄和狀態欄更改顏色以進行材質設計。下面是我創建的主題:使用Theme.AppCompat時,動作欄顏色不會改變

<!-- Base application theme. --> 
<style name="AppTheme2" parent="Theme.AppCompat"> 
    <!-- colorPrimary is used for the default action bar background --> 
    <item name="android:colorPrimary">#FF5722</item> 
    <!--<item name="android:statusBarColor">#E64A19</item>--> 

    <!-- colorPrimaryDark is used for the status bar --> 
    <item name="android:colorPrimaryDark">#E64A19</item> 


    <!-- colorAccent is used as the default value for colorControlActivated 
     which is used to tint widgets --> 
    <item name="android:colorAccent">#FF9800</item> 

    <!-- You can also set colorControlNormal, colorControlActivated 
     colorControlHighlight & colorSwitchThumbNormal. --> 

</style> 

但是,當運行狀態欄更改顏色正常,但操作欄保持黑色。我知道這可能是一個簡單的答案,但我錯過了什麼?

此問題與建議的問題不重複。請刪除國旗。

+0

嘗試改變父主題'Theme.AppCompat.Light.NoActionBar' –

+0

[使用AppCompat更改操作欄的背景顏色](http://stackoverflow.com/ques蒸發散/ 23155637 /改變背景色的最使用-動作杆-程序兼容性) – hungryghost

回答

5

由於您使用的是AppCompat,因此您應該使用AppCompat屬性,而不是Android系統屬性。

變化

colorPrimary 

整個事情應該是這樣的:

<!-- Base application theme. --> 
<style name="AppTheme2" parent="Theme.AppCompat"> 
    <!-- colorPrimary is used for the default action bar background --> 
    <item name="colorPrimary">#FF5722</item> 

    <!-- colorPrimaryDark is used for the status bar --> 
    <item name="colorPrimaryDark">#E64A19</item> 

    <!-- colorAccent is used as the default value for colorControlActivated 
     which is used to tint widgets --> 
    <item name="colorAccent">#FF9800</item> 
</style> 
1

colorPrimary刪除android:appcompat-v7在主題中不使用android:前綴,最後我檢查了它。