Reputation: 175
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" >
Upvotes: 2
Views: 924
Reputation: 175
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>
Upvotes: 0
Reputation: 363895
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.
Upvotes: 1