Change Background color of the action bar using AppCompat

I found some questions about this problem around the web. Unfortunately, everything i try so far, has been unsuccessful.

Has the title say, i need to change the background color of my action bar.

  • How to call layout xml from another module
  • How to find serial number of Android device?
  • How to programmatically read the date when my Android apk was built?
  • android statistic 3g traffic for each APP, how?
  • How to disable onItemSelectedListener to be invoked when setting selected item by code
  • How to set layout_margin programmatically?
  • The project have a min sdk of 9, and max sdk of 19.

    I have create in my res/values folder, an xml file:

    red_actionbar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
            <item name="actionBarStyle">@style/MyActionBar</item>
        </style>
        <style name="MyActionBar"
               parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="background">@color/red</item>
        </style>
    </resources>
    

    the colors.xml stored in res/values

    <resources>
        <color name="red">#FF0000</color>
    </resources>
    

    and the part of the manifest where i change the theme

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

    But nothing changes. Where is the problem? The application accepts the code because if i change ths:

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

    to

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

    it does change the theme of my app, so the problem is in the style but I don’t know how to solve it.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
            <item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
            <item name="actionBarStyle">@style/MyActionBar</item>
        </style>
        <style name="MyActionBar"
               parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
            <item name="android:background"  tools:ignore="NewApi">@color/red</item>
            <item name="background">@color/red</item>
        </style>
    </resources>
    

  • What is Dalvik and dalvik-cache?
  • android shape with bottom stroke
  • Why isn't setVisibility working on Android ProgressBar?
  • Manifest merger failed : uses-sdk:minSdkVersion 14
  • Camera autofocus callback not happening
  • Is there a convenient way to create Parcelable data classes in Android with Kotlin?
  • 4 Solutions collect form web for “Change Background color of the action bar using AppCompat”

    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background"  tools:ignore="NewApi">@color/red</item>
        <item name="background">@color/red</item>
    </style>
    
    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle"   tools:ignore="NewApi">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
    
    </style>
    

    you need both android:background and background items. The former is for newer versions of android that support ActionBar natively. The latter is for older android versions.

    EDIT

    instead of <resources> use

    <resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
    

    From SDK 21

    to change Action Bar background color, add this to ActionBarTheme, and the two colours are to be different or it will not work (thanks to @Dre and @lagoman)

    <item name="colorPrimary">@color/my_awesome_red</item> 
    <item name="colorPrimaryDark">@color/my_awesome_darker_red</item>
    

    Try this:

    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
    
    </style>
    
    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    
        <item name="android:background">@color/red</item>
        <item name="background">@color/red</item>
    
    </style>
    

    Try this.

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary"> #6699FF </item>
    </style>
    

    You can change #6699FF color according to your choice (or use a color resource).

    try to use

    parent="Theme.AppCompat.Light"
    

    instead of

    parent="@style/Theme.AppCompat.Light"
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.