Reputation: 1566
I want to change textcolor of menu items. below is my xml layout for menu -
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/a_More"
android:icon="@drawable/icon_menu_titleview"
android:showAsAction="always">
<menu>
<item
android:id="@+id/action_titleview"
android:icon="@drawable/icon_menu_titleview"
android:showAsAction="never"
android:title="@string/title_view"/>
<item
android:id="@+id/action_listview"
android:icon="@drawable/icon_menu_list_view"
android:showAsAction="never"
android:title="@string/list_view"/>
<item
android:id="@+id/action_magazineview"
android:icon="@drawable/icon_menu_magazine_view"
android:showAsAction="never"
android:title="@string/magazine_view"/>
<item
android:id="@+id/action_cardview"
android:icon="@drawable/icon_menu_card_view"
android:showAsAction="never"
android:title="@string/card_view"/>
</menu>
</item>
</menu>
I don't know which property to use. Thanks in advance
Upvotes: 2
Views: 2072
Reputation: 1
All the answers above will work only for static coloring, if like me you need to implement the color change dynamically after the menu is already created and displayed you should follow this answer and add a line with the color change, note this method will work always even with the SDK 24.
Just add:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
MenuItem item = menu.findItem(R.id.menuItem);
Button saveButton = item.getActionView().findViewById(R.id.menuButton);
//sets the color
saveButton.setTextColor(Color.RED);
return true;
}
Upvotes: 0
Reputation: 3993
Use this in your menu xml:
<item name="android:itemTextAppearance">@style/mMenuTextApearance</item>
in my theme and
<style name="mMenuTextApearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@color/your_color</item>
</style>
Upvotes: 2
Reputation: 3339
<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>
<style name="myCustomMenuTextApearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@android:color/primary_text_dark</item>
</style>
Upvotes: 3