52

How to change text color of menu item title. I tried to change it as below

<style name="Theme.Kanku.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white</item>
</style>

But it change color only of Action Bar title text, but not menu item text.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Procurares
  • 2,169
  • 4
  • 22
  • 34

11 Answers11

117

Try something like this :

<style name="ThemeName" parent="@style/Theme.Sherlock.Light">
    <item name="actionMenuTextColor">@color/white</item>
    <item name="android:actionMenuTextColor">@color/white</item>
</style>
Deimantas Brandišauskas
  • 1,772
  • 2
  • 23
  • 33
  • Great, it helps me a lot! – Procurares Aug 02 '13 at 11:05
  • 2
    Note that this can be a ColorStateList as described here http://developer.android.com/reference/android/content/res/ColorStateList.html. – QED Jan 04 '14 at 19:02
  • 3
    Any idea how you can programatically change the text colour? I have tried using a SpannableString with SetSpan(New Forground...() but it doesn't work. – Subby May 12 '14 at 14:52
  • 5
    I did not find the unqualified "actionMenuTextColor" was necessary (maybe that's something for Sherlock". I did find that you MUST put the `android:actionMenuTextColor` item in the top-level Theme that's referenced in your manifest. I had mine in the `ActionBarStyle` – Colin M. Sep 24 '14 at 18:20
  • I had `android:actionMenuTextColor` it had default black color adding an additional entry without `android` made it work. Weird... – JakeWilson801 Apr 19 '16 at 20:50
  • 1
    For Api21 and above use..... @color/white – Dinesh Sep 24 '16 at 10:26
  • I found Unqualified actionMenuTextColor is necessary to take effect on Android 5 – Codelicious Aug 17 '20 at 08:27
110

I tried several things but nothing worked for me. Finally this did the trick:

<style name="your_theme" parent="your_parent">
    <item name="android:itemTextAppearance">@style/TextAppearance</item>
</style>

<style name="TextAppearance">
    <item name="android:textColor">@android:color/black</item>
</style>

I didn't use Sherlock themes. This worked for Holo.Light.DarkActionBar.

Jonik
  • 80,077
  • 70
  • 264
  • 372
b00n12
  • 1,428
  • 1
  • 12
  • 16
  • 4
    +1. Unlike the accepted answer, this worked nicely for me on Android 4.0+, using Holo.Light as base theme. – Jonik Jan 11 '14 at 13:28
  • 4
    Anything else need to do? I add this to my styles.xml, but it doesn't work at all. I'm also not using Sherlock themes. This is what I did: – Bagusflyer Feb 19 '14 at 09:36
  • What does your styles.xml look like ? – b00n12 Feb 20 '14 at 09:56
  • At last, after seeing dozens of solutions that either don't work (for me) or are for ActionBarSherlock, this works. – user1987392 Nov 20 '14 at 15:32
  • 1
    That thing is so weird working but just don't know why. Close our eyes and believe. –  Oct 01 '15 at 16:25
  • Wow. Thanks for saving my time. – dev1993 Jan 02 '17 at 09:05
  • 3
    This worked for me, thanks! But seriously how can it be so hard to change the text color of a very specific control? And why are there so many different solutions that seem to work for some and for many others not? This is crazy! – sdippl Feb 23 '17 at 16:36
  • This worked for me. I am using Theme.MaterialComponents.Light.NoActionBar. – prabhatsdp Sep 14 '20 at 02:05
14

After trying all of these and having them not work, I went about it programmatically like this:

public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.changeip_card_menu, menu); 
    for(int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        SpannableString spanString = new SpannableString(menu.getItem(i).getTitle().toString());
        spanString.setSpan(new ForegroundColorSpan(Color.WHITE), 0, spanString.length(), 0); //fix the color to white
        item.setTitle(spanString);
    }
    return true;
}

This will work dynamically every time. In this case, the text color is changed to white. Simpy, change Color.WHITE to Color.whatever-color-you-want to change it to whatever color you want.

Alex K
  • 8,269
  • 9
  • 39
  • 57
7

To update the menu item text color you need to make changes in themes.xml. The following answer is for sherlock.actionbar. In your themes.xml file add following lines:

<style name="Theme.Mytheme" parent="@style/Theme.Sherlock">
    <item name="actionMenuTextColor">@color/mycolor</item>     
    <item name="android:actionMenuTextColor">@color/mycolor</item>
</style> 
Vikas
  • 4,263
  • 1
  • 34
  • 39
5

this worked for me:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:textAppearanceLargePopupMenu">@style/MyOverflowItemCollor</item>       
</style>

<style name="MyOverflowItemCollor" parent="android:TextAppearance.Holo.Widget.PopupMenu.Large">
    <item name="android:textColor">#ffffff</item>
</style> 
kajlaminog
  • 59
  • 1
  • 1
4

If AppTheme is android:Theme.Holo.Light.DarkActionBar, then you need to set custom actionBarWidgetTheme in order to get action menu style changed. Like this:

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarWidgetTheme">@style/ActionBarWidget</item>
    <item name="android:actionMenuTextColor">@color/{custom_menu_item_text_color}</item>
</style>

<style name="MenuItemText">
    <item name="android:textColor">@color/{custom_menu_item_text_color}</item>
</style>

<style name="ActionBarWidget" parent="@android:style/Theme.Holo">
    <item name="android:itemTextAppearance">@style/MenuItemText</item>
</style>
Alexander Zhak
  • 9,140
  • 4
  • 46
  • 72
1

please use the below code it works

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->

    <item name="colorPrimary">@color/colorWhite</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimaryDark</item>
    <item name="android:actionMenuTextColor">@color/colorWhite</item>
</style>

1

Add following line of code into your style.xml file that change option menu text color into black:

 <style name="optionMenuTextApearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
    <item name="android:textColor">@color/colorBlack</item>
</style>

Then add this one line code into your theme to change color of option menu text:

        <item name="android:itemTextAppearance">@style/optionMenuTextApearance</item>

It works for me,Thanks.

AMI CHARADAVA
  • 303
  • 3
  • 9
1

If you use DarkActionBar add below two lines in your style.xml

  1. @color/green
    1. @color/green

Complete code is given below

<!-- 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/green</item>
    <item name="android:actionMenuTextColor">@color/green</item>
</style>

Divyaadz
  • 175
  • 2
  • 11
0

you can change the action item color simply by following line

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

you can apply like this.

<style name="your_theme" parent="your_parent">
<item name="android:actionMenuTextColor">@color/selected_text_color</item>
</style>

In my case

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
  <item name="android:actionMenuTextColor">@color/selected_text_color</item>
  </style>
DjP
  • 4,537
  • 2
  • 25
  • 34
-1

You can set color programmatically. Hope it help you.

private static void setMenuTextColor(final Context context, final Toolbar toolbar, final int menuResId, final int colorRes) {
    toolbar.post(new Runnable() {
        @Override
        public void run() {
            View settingsMenuItem =  toolbar.findViewById(menuResId);
            if (settingsMenuItem instanceof TextView) {
                if (DEBUG) {
                    Log.i(TAG, "setMenuTextColor textview");
                }
                TextView tv = (TextView) settingsMenuItem;
                tv.setTextColor(ContextCompat.getColor(context, colorRes));
            } else { // you can ignore this branch, because usually there is not the situation
                Menu menu = toolbar.getMenu();
                MenuItem item = menu.findItem(menuResId);
                SpannableString s = new SpannableString(item.getTitle());
                s.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, colorRes)), 0, s.length(), 0);
                item.setTitle(s);
            }

        }
    });
}
Victor Choy
  • 4,006
  • 28
  • 35