Change Android 5.0 Actionbar color

10,581

AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">

    <item name="colorPrimary">@color/primaryDef</item>
    <item name="colorPrimaryDark">@color/primaryDarkDef</item>
    <item name="colorAccent">@color/primaryDef</item>

    <item name="android:navigationBarColor">@color/primaryDarkDef</item>
    <item name="android:activatedBackgroundIndicator">@drawable/defbg</item>
</style>

The Action Bar will be colored by colorPrimary.

Share:
10,581
Plays2
Author by

Plays2

Updated on July 22, 2022

Comments

  • Plays2
    Plays2 almost 2 years

    I'm working with the new Lollipop Material Design guidelines and would like to incorporate that nifty navigation drawer animation in my app. I've gotten that far, by using the android.support.v7.app.ActionBarDrawerToggle, but now I'm having difficulty changing the color of said action bar. It stays bright gray no matter what I set the theme to. How would one go about changing the color of the actionbar? This is what my app theme looks like:

    //res/values/styles.xml
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    
        <item name="android:actionBarStyle">@style/ActionBar</item>
        <item name="android:colorPrimary">@color/primaryDef</item>
        <item name="android:colorPrimaryDark">@color/primaryDarkDef</item>
        <item name="android:activatedBackgroundIndicator">@drawable/defbg</item>
        <item name="android:colorAccent">@color/primaryDef</item>
        <item name="android:navigationBarColor">@color/primaryDarkDef</item>
    
    </style>
    
    <style name="ActionBar" parent="android:Widget.ActionBar">
        <item name="android:background">@color/primaryDef</item>
    </style>
    
  • Plays2
    Plays2 over 9 years
    But my FAB, which usually matches the colorPrimary, is black, while it should be blue...
  • Qianqian
    Qianqian over 9 years
    This used to work days ago, but after I updated the appcompat support library yesterday or so (to rev 21.0.1), it suddenly did not work for Android 5.0. That is for pre-L versions, the actoinbar shows as colorPrimary defines, but on Android 5.0, it is always transparent. Do you face this (problem)?
  • ianhanniballake
    ianhanniballake over 9 years
    @Qianqian - 21.0.1 didn't change anything with AppCompat (only added the Multidex library) so if it worked with 21.0.0 it is something else you changed.
  • Qianqian
    Qianqian over 9 years
    @ianhanniballake, Thank you very much for the answer. I just figured out that I got the problem because I re-define the actionbar style to remove the elevation for v21...