Change ActionBar title text color using Light.DarkActionBar theme in AppCompat 21

weiyin picture weiyin · Nov 11, 2014 · Viewed 62.6k times · Source

I'm using the v7 appcompat 21 library to use the new Material styles on pre-Lollipop devices. My styles.xml looks like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:textColorPrimary">#ff0000</item>
    <item name="android:textColorPrimaryInverse">#ff0000</item>
</style>

I am trying to change the text color on the action bar. But no matter what I put for textColorPrimary or textColorPrimaryInverse, the color is always white. If I inherit from Theme.AppCompat, I can override "textColorPrimary", and if I inherit from Theme.AppCompat.Light, I can override "textColorPrimaryInverse". But neither work when using the Light.DarkActionBar theme.

I am definitely using the AppTheme because setting attributes like colorPrimary to change the actionbar background color works fine. I am not using any other resource qualifier style files.

I've dug through the android styles files and can't seem to figure out what attribute to override. Any ideas? Is this an appcompat bug?

Answer

jimmy0251 picture jimmy0251 · Nov 11, 2014

You can change it with actionBarStyle attribute of theme.

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/MyTitleTextStyle</item>
</style>

<style name="MyTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">CHANGE_COLOR_HERE</item>
</style>