57
votes

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?

7

7 Answers

172
votes

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>
26
votes

This will make your Toolbar Title use white color:

<android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary" />

To understand what is the difference between ThemeOverlay.AppCompat.Dark.ActionBar and Theme.AppCompat.Light.DarkActionBar check this answer

It's app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" that applies a light colour because the title colour which is used in this theme is white.

4
votes

make sure you make the changes in all your values folder, like 'values-v11', 'values-v14' etc.. if it exists.

Else make sure the same 'AppTheme' you shown above is being used in the app.

Please post you full style.xml and the manifest code referring the style which will give more insights on your problem.

Also you can try setting app:theme and app:popupTheme attributes on you ToolBar.

3
votes

Try adding this in the onCreate of your Activity. Works on almost every Android version.

For Java Activities:

actionBar.setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));  

For Fragments:

getSupportActionBar().setTitle(Html.fromHtml("<font color='#ffff00'>Your Title</font>"));
1
votes

I used a generated layout xml file and didn't notice that the android:theme attribute was overriden.

Did you check yours? :)

1
votes

Unfortunately I struggled a lot to change the color of App name. I was having many themes. Finally what worked for me is changing below two attributes.

    <item name="android:textColorPrimary">#FF0000</item>
    <item name="android:textColorSecondary">#FF0000</item>
-3
votes

Try this:

<item name="actionMenuTextColor">@color/red</item>