0

I have this code in my Activity:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("My title");

In styles.xml, I have this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    //more stuff
</style>

<style name="Toolbar" parent="Theme.AppCompat">
    <item name="android:textAppearance">@style/Toolbar.Text</item>
</style>

<style name="Toolbar.Text">
    <item name="android:textColor">@android:color/white</item>
</style>

and the Toolbar layout:

  <android.support.v7.widget.Toolbar
     android:id="@+id/toolbar"
     android:layout_width="match_parent"
     android:layout_height="?attr/actionBarSize"
     app:layout_collapseMode="pin"
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
     app:theme="@style/Toolbar" />

I want the toolbar's text to be white, but it is black. I have tried lot of things but I really can't change it.

Héctor
  • 24,444
  • 35
  • 132
  • 243

3 Answers3

1

Whatever it is, The issue is come from this line :

<style name="Toolbar" parent="Theme.AppCompat">

And this: app:theme="@style/Toolbar" (You've used app instead of android, Be careful about that)

And you don't really need to do that.


Just use this line for the Toolbar:

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

So:

<android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/AppTheme" />

Then you should see the white text and etc

As you can see, I've set the app:popupTheme to AppTheme which the parameter is :

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

After adding that line to the Toolbar, Now you can remove these:

<style name="Toolbar" parent="Theme.AppCompat">
    <item name="android:textAppearance">@style/Toolbar.Text</item>
</style>

<style name="Toolbar.Text">
    <item name="android:textColor">@android:color/white</item>
</style>

Then the only thing you should do is setting the parent for app:popupTheme to this :

Theme.AppCompat.Light.NoActionBar

Which it can be your Activity style parent.

That's it :)

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
0

Use the editor for this. Go to tools->android->theme editor. There you can find the option for changing the colors.

Simo
  • 345
  • 4
  • 12
  • I have been able to change the text color by changing textColorPrimary in the app main style, but it changes all the text in another components, too. I just want it in the toolbar – Héctor Jan 07 '17 at 20:01
  • May be [this](http://stackoverflow.com/questions/26969424/how-to-set-toolbar-text-and-back-arrow-color) will help you. – Simo Jan 07 '17 at 20:28
  • and also, may be you have set the textColorPrimery for other texts too and hence the result. – Simo Jan 07 '17 at 20:31
  • I have tried all the answers of the link and it doesn't work for me. – Héctor Jan 07 '17 at 20:39
  • I'm using data binding in layout, does it matter? – Héctor Jan 07 '17 at 20:40
-1

you may be using SDK less than 23 you can try this

In xml :-

android:titleTextColor="@color/colorPrimary"

In fragment

 toolbar.setTitleTextColor(Color.RED);
santosh kumar
  • 2,952
  • 1
  • 15
  • 27