ziwert ziwert - 1 year ago 48
Android Question

Toolbar's custom text color is not used

I'm trying customize the ActionBar in my app. I want to change background color and text color.


is as below:


<!-- Base application theme. -->
<style name="AppTheme.NoActionBar" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

<item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>

<!-- Support library compatibility -->
<item name="actionBarStyle">@style/AppTheme.ActionBar</item>

<style name="AppTheme.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">@color/actionbar_background</item>
<item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>

<!-- Support library compatibility -->
<item name="background">@color/actionbar_background</item>
<item name="titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>

<style name="AppTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text_color</item>


In my
I added
. In my activity I added the action bar with code

app:theme="@style/AppTheme.ActionBar" />

In result I have the action bar with correct color but incorrect text color.

What's wrong?

I'm using AppCompat, not Holo or other.

Answer Source

This is happening because your Toolbar's theme is set to light, hence the Android picks a dark (black) text colour.

You need to update it to following:

<style name="AppTheme.ActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="titleTextColor">#FF0001</item>
    <item name="subtitleTextColor">#FF0001</item>
    <!-- your other theme attributes -->


  1. For Toolbar themes, use ThemeOverlay instead of Theme.AppCompat. Related - When should one use Theme.AppCompat vs ThemeOverlay.AppCompat?,
  2. replace #FF0001 with any colour you like. This is the colour of your title text.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download