Created
May 27, 2015 00:10
-
-
Save aows/0bdd2ead2fb2ed1d4872 to your computer and use it in GitHub Desktop.
Changing text color of a MenuItem programmatically (Android)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onPrepareOptionsMenu(Menu menu) { | |
MenuItem settingsMenuItem = menu.findItem(R.id.action_settings); | |
SpannableString s = new SpannableString(settingsMenuItem.getTitle()); | |
s.setSpan(new ForegroundColorSpan(yourColor), 0, s.length(), 0); | |
settingsMenuItem.setTitle(s); | |
return super.onPrepareOptionsMenu(menu); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i found a better solution i think.
Go in your menu xml and add to your items (if you don't use androidx use normal text view)
Then this works: