[android] How to change the Text color of Menu item in Android?

You can change the color of the MenuItem text easily by using SpannableString instead of String.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.your_menu, menu);

    int positionOfMenuItem = 0; // or whatever...
    MenuItem item = menu.getItem(positionOfMenuItem);
    SpannableString s = new SpannableString("My red MenuItem");
    s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
    item.setTitle(s);
}

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks How to add "active" class to wp_nav_menu() current menu item (simple way) How do I hide a menu item in the actionbar? Handling a Menu Item Click Event - Android android: changing option menu items programmatically How to change menu item text dynamically in Android Sql Server 'Saving changes is not permitted' error ? Prevent saving changes that require table re-creation Android: How to enable/disable option menu item on button click? How to change the Text color of Menu item in Android? How do I center align horizontal <UL> menu?

Examples related to textcolor

How can I change default dialog button text color in android 5 How to set textColor of UILabel in Swift With Twitter Bootstrap, how can I customize the h1 text color of one page and leave the other pages to be default? UIButton title text color UILabel with text of two different colors How to change the Text color of Menu item in Android? How do you use NSAttributedString?

Examples related to layout-inflater

onCreateOptionsMenu inside Fragments How does the getView() method work when creating your own custom adapter? Call to getLayoutInflater() in places not in activity How to change the Text color of Menu item in Android? What does LayoutInflater in Android do? How to change the background color of the options menu? How to inflate one view with a layout