user2923535
user2923535

Reputation: 594

How to change the color of the text in the toolbar options

I accidentally deleted my color.xml file and as I've rebuilt it, I'm unable to fix this one problem. The color of the text in the options for toolbar buttons is white on white. It wasn't like that before(It was black text before) but I'm not sure how to fix it.

Here's an image of what I mean: https://i.sstatic.net/k79Ba.jpg

And here's my styles.xml file:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/accent_color</item>
        <item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
        <item name="android:textColorSecondary">@color/abc_primary_text_material_dark</item>



    </style>

    <style name="FabStyle">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_margin">16dp</item>
        <item name="borderWidth">0dp</item>
        <item name="elevation">6dp</item>
        <item name="pressedTranslationZ">12dp</item>
        <item name="rippleColor">@android:color/white</item>
    </style>

    <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">@color/accent_color</item>
    </style>


</resources>

And for good measure my colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <!--<color name="accent_color">#69F0AE</color>-->
    <color name="dialog_color">#4db6ac</color>
    <color name="accent_color">#FF4081</color>
    <color name="background_light">#fafafa</color>
    <color name="background">#ffffff</color>
    <color name="text_color">#000000</color>
    <color name="score_color">#9e9e9e</color>
</resources>

Here is the toolbar initialized in the MainActivity:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Here is the toolbar in my activty xml file:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:theme="@style/AppTheme"
    android:elevation="6dp"
    app:popupTheme="@style/AppTheme"
    />

Upvotes: 0

Views: 1029

Answers (1)

Rico Teng
Rico Teng

Reputation: 236

You can try this, change your toolbar theme:

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

Add the popupTheme to your toolbar.

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

Upvotes: 2

Related Questions