4

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:

enter image description here

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"
3

1 Answer 1

2

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.