[英]change color of menu button when pressed in android
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: 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"
The best and easiest way is to make your own style 最好和最简单的方法是制作自己的风格
In this case, style name is Menu 在这种情况下,样式名称是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 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"
如果您想在收费栏中使用该菜单,只需添加此
app:popupTheme="@style/Menu"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.