Change Material Design AppCompat ActionBar Color

Theme.MaterialComponents

<style name="Theme.EmojiBible" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="actionBarTheme">@style/ThemeOverlay.Actionbar</item>
</style>

<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" >
    <item name="android:textColorPrimary">#f00</item>
</style>

In my case, @reVerse had a partial answer. I had to make some additional changes to get colorPrimary to work, because I was customizing other parts of the toolbar... specifically, the text color.

Here is my working styles.xml file, with comments indicating what I was doing wrong:

<!-- As @reVerse mentioned, you need to use colorPrimary instead of android:colorPrimary -->
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/my_toolbar_color</item>
</style>

<!-- I was incorrectly using @style/Theme.AppCompat.Light for the popupTheme attribute -->
<style name="MyToolbarStyle" parent="Widget.AppCompat.ActionBar">
    <item name="theme">@style/MyToolbarTextStyle</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
</style>

<!-- I was incorrectly using Them.AppCompat.Light for the parent here -->
<style name="MyToolbarTextStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/my_toolbar_text_color</item>
</style>

So, when customizing more than the toolbar background color, you need to be sure to use one of the ThemeOverlay themes or, for whatever reason, colorPrimary will be ignored.

For completeness, here is the layout file I use for my toolbar, Toolbar.xml:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schmeas.android.com/apk/res-auto"
    style="@style/MyToolbarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Hopefully this helps someone!


There's a new attribute called colorPrimary which you can define in your Theme. This will give you ActionBar or Toolbar a solid color.

Following a little example:

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">@color/my_action_bar_color</item>
</style>

Please note: It has to be only colorPrimary, not android:colorPrimary, in every values-folder except the values-v21 one.

You can read more about customizing the Color Palette on developer.android.com.