Reputation:
I make custom menu item which have color background I want when button press that item button menu selected become to another color like below image:
and its my custom style :
<style name="Menu">
<item name="android:colorBackground">@color/white</item>
<item name="android:textColor">@color/colorAccent</item>
<item name="android:background">@drawable/item_bg_menu</item>
</style>
item_bg_menu:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/white" />
<item
android:state_pressed="true"
android:drawable="@color/gray" />
</selector>
and it is way i use menu:
app:popupTheme="@style/Menu"
Upvotes: 4
Views: 2123
Reputation: 3353
The best and easiest way is to make your own style
In this case, style name is Menu
<style name="Menu">
<item name="android:colorBackground">@color/gray</item> //color of background menu
<item name="android:textColor">@color/white</item> //text color
<item name="android:listSelector">@drawable/item_bg_menu</item> //this is for when button press color changed
</style>
item_bg_menu
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/black" /> //color when button press
</selector>
and where you want use that menu in your toll bar just add this app:popupTheme="@style/Menu"
Upvotes: 2