更改 Appcompat 主题的操作栏颜色
Change the Actionbar Color of an Appcompat Theme
我想为我的操作栏实现一种略带橙色的颜色。问题是,我正在为我的应用程序使用 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 主题中操作栏的颜色?
使用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>
另请参阅 post 来自 google 开发者的博客
我想为我的操作栏实现一种略带橙色的颜色。问题是,我正在为我的应用程序使用 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 主题中操作栏的颜色?
使用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>
另请参阅 post 来自 google 开发者的博客