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.

2

11 Answers 11

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>
6
  • 2
    Note that this can be a ColorStateList as described here developer.android.com/reference/android/content/res/….
    – QED
    Jan 4, 2014 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, 2014 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 <style> group and it did NOT work there.
    – Colin M.
    Sep 24, 2014 at 18:20
  • I had android:actionMenuTextColor it had default black color adding an additional entry without android made it work. Weird... Apr 19, 2016 at 20:50
  • 1
    For Api21 and above use..... <item name="android:textColorPrimary">@color/white</item>
    – Dinesh
    Sep 24, 2016 at 10:26
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.

8
  • 4
    +1. Unlike the accepted answer, this worked nicely for me on Android 4.0+, using Holo.Light as base theme.
    – Jonik
    Jan 11, 2014 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: <style name="AppTheme" parent="Theme.MyTheme"> <item name="android:itemTextAppearance">@style/TextAppearance</item> </style> <style name="TextAppearance"> <item name="android:textColor">@android:color/darker_gray</item> </style>
    – Bagusflyer
    Feb 19, 2014 at 9:36
  • What does your styles.xml look like ?
    – b00n12
    Feb 20, 2014 at 9:56
  • 1
    That thing is so weird working but just don't know why. Close our eyes and believe.
    – user5156016
    Oct 1, 2015 at 16:25
  • 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, 2017 at 16:36
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.

5
  • @kenyee which version of Android?
    – Alex K
    Dec 6, 2014 at 21:57
  • @kenyee interesting. I used this code in a 4.4.x app for work. It worked fine for me.
    – Alex K
    Dec 29, 2014 at 3:41
  • @Hammer which version of android?
    – Alex K
    Jan 17, 2015 at 16:16
  • @Hammer All right, I'll do some investigating and figure out why it may not be working
    – Alex K
    Jan 17, 2015 at 16:22
  • 1
    Worked for me. Style manipulation also worked, but I didn't find a way to change menu item color without changing action bar title color. However, this is weird.
    – LVR
    Jan 26, 2017 at 15:18
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> 
1
  • Why is item name="actionMenuTextColor" necessary? Oct 27, 2015 at 17:24
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> 
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>
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>

0
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.

0
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>

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>
-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);
            }

        }
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.