Search code examples
android-studioandroid-actionbarandroid-theme

Android action bar not reflecting color change


I've read numerous answers regarding changing the color of the action bar, but I can't seem to get it to work. Here's what I have:

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="Theme.AppCompat.Light">
        <item name="android:windowBackground">@color/actionBarBackground
        </item>
    </style>
    </resources>

I've also tried

<item name="android:Background">#F33</item>

AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

Solution

  • The following seems to have done the trick. I found it here Change Background color of the action bar using AppCompat

    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>
    
    <!-- ActionBar styles -->
    <style name="MyActionBar" parent="Theme.AppCompat.Light">
        <item name="android:background">@color/actionBarBackground</item>
        <item name="background">@color/actionBarBackground</item>
    </style>
    

    However, now my android:label in my manifest file is being covered by the background color, so I added

    <item name="android:displayOptions">showTitle</item>
    <item name="displayOptions">showTitle</item>