2

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" >
Cliff
  • 175
  • 1
  • 8

2 Answers2

1

You are changing the android:windowBackground not the background of your ActionBar.

In any case, starting with the AppCompat v21+, you can use a new way to customize your ActionBar.

  • All of your Activities must extend from AppCompatActivity

  • All of your themes (that want an ActionBar/Toolbar) must inherit from Theme.AppCompat.

Just use a theme like this:

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- Set AppCompat’s color theming attrs -->
    <item name="colorPrimary">@color/my_awesome_red</item>
    <item name="colorPrimaryDark">@color/my_awesome_darker_red</item>

    <!-- The rest of your attributes -->
</style>

The current version of AppCompat is 23. It requires API23 to compile the project.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • All of my activities already extend `AppCompatActivity` The code you posted seems identical to what I have unless I'm missing something. I added my style in the activity in the manifest itself and that changed the background once the app called that activity, but that only works for activities. Should there be an activity for the action bar? There's clearly a concept somewhere I'm missing. – Cliff Sep 02 '15 at 00:30
  • @Cliff I don't know if you are using a Toolbar in your layout.In this case post your code. If not, the color of actionbar is defined by the colorprimary attrr in the theme used by the activity. In your theme I don't see it. – Gabriele Mariotti Sep 02 '15 at 05:50
  • in menu_main I have ` ` – Cliff Sep 02 '15 at 22:51
  • to be honest I'm not sure where the action bar is created code-wise since it is automatically added when I set the minimum sdk to 11. I populate it via the code above, but it's confusing to me how to manipulate it's layout, and I'm not really sure the best way to go about it – Cliff Sep 02 '15 at 22:53
0

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>
Community
  • 1
  • 1
Cliff
  • 175
  • 1
  • 8