Mansour Fahad
Mansour Fahad

Reputation: 735

How to change the background color of the action bar in Android?

I was working hard to achieve this but I had no luck. What I tried to do is to change the background color from the style that I attached in my main style tag. This is my code:

<resources>

<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item ></item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#2E495E</item>
</style>

Still nothing changed. I get this in my application:

https://i.sstatic.net/s0i51.png

Upvotes: 1

Views: 9861

Answers (2)

Daniel Wilson
Daniel Wilson

Reputation: 19834

I had the same issue and it's probably the same problem you were having. Notice the docs say the following:

each style property that you declare must be declared twice..

So my issue was I declared it for 2.1 and up, but not for 3.0 and greater so my Galaxy S4 of course could not see any changes to the colours I was making.

<resources>

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

    <!--Support Library compatibility-->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
    parent="@style/Widget.AppCompat.Light.ActionBar">

    <item name="android:background">@color/green</item>

    <!--Support Library compatibility-->
    <item name="background">@color/green</item>
</style>

<style name="NoActionBar" parent="Theme.AppCompat.Light">
    <item name="android:windowNoTitle">true</item>
</style>

Upvotes: 4

Archie.bpgc
Archie.bpgc

Reputation: 24012

Is this the only style.xml you have? Else check if you are modifying for the right API

Upvotes: 2

Related Questions