How to change menu item's text background while clicking on it? The higlight color on whole item is right, but it seems that text has it's own background color. I think that deal is in settin on app:popupTheme, but I don't know what style parameters I should set.
Asked
Active
Viewed 549 times
2 Answers
0
Kindly Use this and set the desired color.
@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 MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
}

Fathima km
- 2,539
- 3
- 18
- 26
0
Please check How to change the background color of Action Bar's Option Menu in Android 4.2?
and for change text color : Setting the "android:textColor" will work
<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
...
<!--This would set the menu item color-->
<item name="android:textColor">#000</item>
...
</style>

Community
- 1
- 1

Amit Vaghela
- 22,772
- 22
- 86
- 142
-
It doesn't work. The text color is changed, but color of the text background - is still white (it must be gray), when highlight color of whole item is gray. – user3352926 Apr 10 '17 at 07:26
-
plz go through link i have provided in answer@user3352926 – Amit Vaghela Apr 10 '17 at 12:34