57

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?

weiyin
  • 6,819
  • 4
  • 47
  • 58

7 Answers7

172

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>
jimmy0251
  • 16,293
  • 10
  • 36
  • 39
  • 26
    For some reason setting the textColor the way you did has no effect when running on Android 5 or Android 4 device (those are the two i have tested it on) - any ideas? I am using Toolbar with AppCompatActivity and apply above theme in my manifest. – AgentKnopf Jul 29 '15 at 18:10
  • 6
    @AgentKnopf This will work only with ActionBar. You have to set your ToolBar as an ActionBar in order for this to work. – jimmy0251 May 03 '16 at 03:16
  • 1
    This is not working for me. I am using toolbar and set it as actionbar. I have used Theme.AppCompat.Light.NoActionBar for my app and ThemeOverlay.AppCompat.Dark.ActionBar for AppBarLayout and style ThemeOverlay.AppCompat.Light for toolbar – Rakesh Yadav Mar 30 '18 at 07:33
  • I'd really like to know what this would look like if it is possible to compress the three style resources under one parent xml tag – Harsha May 07 '18 at 15:04
  • What about styling of the subtitle ? How would that go ? – mirzak May 21 '18 at 12:56
26

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.

vovahost
  • 34,185
  • 17
  • 113
  • 116
4

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.

Sreekanth
  • 2,887
  • 2
  • 16
  • 30
3

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>"));
Manaus
  • 407
  • 5
  • 9
onexf
  • 3,674
  • 3
  • 22
  • 36
2

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>
Anajaleena Oliver
  • 121
  • 1
  • 1
  • 5
1

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

Did you check yours? :)

DoruChidean
  • 7,941
  • 1
  • 29
  • 33
-3

Try this:

<item name="actionMenuTextColor">@color/red</item>
Roberto Betancourt
  • 2,375
  • 3
  • 27
  • 35