Action Bar menu item text color

AndroidAndroid ActionbarAndroid MenuAndroid Styles

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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>

Solution 2 - Android

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.

Solution 3 - Android

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.

Solution 4 - Android

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> 

Solution 5 - Android

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> 

Solution 6 - Android

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>

Solution 7 - Android

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>

Solution 8 - Android

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.

Solution 9 - Android

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

  1. @color/green
  2. @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>

Solution 10 - Android

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>

Solution 11 - Android

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

        }
    });
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionProcuraresView Question on Stackoverflow
Solution 1 - AndroidDeimantas BrandišauskasView Answer on Stackoverflow
Solution 2 - Androidb00n12View Answer on Stackoverflow
Solution 3 - AndroidAlex KView Answer on Stackoverflow
Solution 4 - AndroidVikasView Answer on Stackoverflow
Solution 5 - AndroidkajlaminogView Answer on Stackoverflow
Solution 6 - AndroidAlexander ZhakView Answer on Stackoverflow
Solution 7 - AndroidUpendranath ReddyView Answer on Stackoverflow
Solution 8 - AndroidAMI CHARADAVAView Answer on Stackoverflow
Solution 9 - AndroidDivyaadzView Answer on Stackoverflow
Solution 10 - AndroidDjPView Answer on Stackoverflow
Solution 11 - AndroidVictor ChoyView Answer on Stackoverflow