Varun Joshi
Varun Joshi

Reputation: 689

Unable to change the Color of the Menu option on the Android Toolbar

been trying to change the color of the menu items that appear on the Toolbar.

Here is my menu xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/action_settings"
        android:title="Settings"
        app:showAsAction="never"
        android:orderInCategory="100"/>

    <item android:id="@+id/always"
        android:title="Always"
        app:showAsAction="always"
        android:orderInCategory="101"/>

    <item android:id="@+id/never"
        android:title="Never"
        app:showAsAction="never"
        android:orderInCategory="102"/>

    <item android:id="@+id/ifroom"
        android:title="If Room"
        android:orderInCategory="103"
        app:showAsAction="ifRoom"/>

    <item android:id="@+id/always1"
        android:title="Always1"
        app:showAsAction="always"
        android:orderInCategory="104"/>

</menu>

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="actionMenuTextColor">@color/white</item>
        <item name="android:actionMenuTextColor">@color/white</item>
    </style>

</resources>

I've tried using the style options but I cannot figure out how to change the color. The actionMenuTextColor & android:actionMenuTextColor do not solve the problem. It still appears black. Which looks untidy on my blue background.

Upvotes: 1

Views: 1824

Answers (2)

Varun Joshi
Varun Joshi

Reputation: 689

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:background="@color/colorPrimary">

    </android.support.v7.widget.Toolbar>

Turns out I was inheriting the wrong theme! This works for me!

Upvotes: 5

Harshad Pansuriya
Harshad Pansuriya

Reputation: 20990

Remove this line in styles.xml

<item name="actionMenuTextColor">@color/white</item>
<item name="android:actionMenuTextColor">@color/white</item>

and add this

<item name="android:textColor">@color/red</item>
<item name="android:itemBackground">@color/skyBlue</item>

Complete code :

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:textColor">@color/red</item>
        <item name="android:itemBackground">@color/skyBlue</item>
    </style>

Upvotes: 1

Related Questions