2015-04-12 58 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

谢谢你,工作这篇博客。 –