2015-04-12 56 views
1

我想爲我的操作欄實現某種橙色。問題是,我使用的是程序兼容性主題我的應用程序:更改Appcompat主題的操作欄顏色

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

</style> 
<style name="menu_labels_style"> 
    <item name="android:background">@drawable/fab_label_background</item> 
    <item name="android:textColor">@color/white</item> 
</style> 

</resources> 

所以通常的方式有:

<resources> 
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
     <item name="android:actionBarStyle">@style/MyActionBar</item> 
    </style> 

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar"> 
     <item name="android:background">#F39530</item> 
    </style> 
</resources> 

(例如),將無法正常工作。那麼如何在AppCompat主題中更改操作欄的顏色?

回答

2

使用colorPrimary設置顏色,如

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 

     <!-- colorPrimary is used for the default action bar background --> 
     <item name="colorPrimary">@color/background_green</item> 

     <!-- colorPrimaryDark is used for the status bar --> 
     <item name="colorPrimaryDark">@color/background_green</item> 

     <!-- colorAccent is used as the default value for colorControlActivated, 
      which is used to tint widgets --> 
     <item name="colorAccent">@color/darkgreen_activeTextColor</item> 
<style> 

另見谷歌開發者

AppCompat v21 — Material Design for Pre-Lollipop Devices

+0

謝謝你,工作這篇博客。 –