简体   繁体   English

更改Appcompat主题的操作栏颜色

[英]Change the Actionbar Color of an Appcompat Theme

I want to achieve a somewhat orange color for my actionbar. 我想为我的动作栏获得一些橙色。 The problem is, I am using an appcompat theme for my app: 问题是,我正在为我的应用程序使用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>

So the usual way with: 通常的方式是:

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

(for example), won't work. (例如),将无法正常工作。 So how do I change the color of the actionbar in an AppCompat theme? 那么如何更改AppCompat主题中操作栏的颜色?

Use colorPrimary to set the color, as in 使用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>

See also this blog post from google devs 另请参阅Google开发者的此博客文章

AppCompat v21 — Material Design for Pre-Lollipop Devices AppCompat v21 - 前棒棒糖设备的材料设计

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM