mwieczorek
mwieczorek

Reputation: 2252

Cannot alter Toolbar Text and Icon Colors

I've been struggling with this all day - I've been on Stack Overflow for hours trying various solutions to no avail.

The application I'm building uses the light material theme, yet the text on the toolbar refuses to change from anything but black. The toolbar itself colors perfectly.

styles.xml:

<resources>
    <style name="AppTheme" parent="AppTheme.Base">
    </style>
    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:colorAccent">@color/accent</item>
    </style>
    <style name="Toolbar" parent="ThemeOverlay.AppCompat.Dark">
        <item name="android:background">@color/primary</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:titleTextColor">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:color">@color/white</item>
        <item name="android:elevation">@dimen/toolbar_elevation</item>
    </style>
</resources>

in the activity layout file:

<android.support.v7.widget.Toolbar
    android:id="@+id/main_toolbar"
    style="@style/Toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:title="@string/app_name" />

Hoping someone can help solve this issue.

Upvotes: 1

Views: 557

Answers (1)

ʍѳђઽ૯ท
ʍѳђઽ૯ท

Reputation: 16976

Add this to your Toolbar:

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

Or perhaps, Adding this:

ThemeOverlay.AppCompat.Dark.ActionBar instead of ThemeOverlay.AppCompat.Dark you forgot to add ActionBar at the end i guess.

And of course, If you have AppBarLayout, Try to add this line in your AppBarLayout too:

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

Texts will be white.


Otherwise, This answer will help:

Option 1) The quick and easy way (Toolbar only)

Since appcompat-v7-r23 you can use the following attributes directly on your Toolbar or its style:

app:titleTextColor="@color/primary_text"
app:subtitleTextColor="@color/secondary_text"

Upvotes: 2

Related Questions