更改Appcompat主题的操作栏颜色

时间:2015-04-12 19:12:10

标签: java android xml android-studio android-styles

我想为我的动作栏获得一些橙色。问题是,我正在为我的应用程序使用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主题中操作栏的颜色?

1 个答案:

答案 0 :(得分:3)

使用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>

另请参阅Google开发者的博客文章

AppCompat v21 — Material Design for Pre-Lollipop Devices