justdeko
justdeko

Reputation: 1124

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:

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

Upvotes: 2

Views: 1573

Answers (1)

Sanj
Sanj

Reputation: 850

Use colorPrimary to set the color, as in

<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

AppCompat v21 — Material Design for Pre-Lollipop Devices

Upvotes: 4

Related Questions