简体   繁体   English

按下时,ActionBar会更改menuitem按钮的颜色

[英]ActionBar change color of menuitem button when pressed

How to change color of menuitem button when it pressed. 如何在按下时更改menuitem按钮的颜色。 I use SherlockActionBar but when it pressed it changes color to one that it not really good for my design. 我使用SherlockActionBar,但是当它被按下时,它会改变颜色,使其对我的设计不太好。 I need to change this color. 我需要改变这种颜色。

Updated: 更新:

The point is when I set drawable i placed on background and when button is pressed then change of bckground near my drawable changes. 关键是当我设置drawable我放在背景上并按下按钮然后更改我的drawable附近的bckground更改。 I can change the drawable, but background will still change it`s color to ugly one. 我可以改变drawable,但背景仍会改变它的颜色到丑陋的颜色。

You can change the background by setting the actionBarItemBackground attribute in your theme. 您可以通过在主题中设置actionBarItemBackground属性来更改背景。 This should be a state-list drawable which reflects states such as pressed and focused. 这应该是一个状态列表drawable,它反映了压缩和聚焦等状态。

This is how you change the icon to a new icon when you click the menu item. 这是单击菜单项时将图标更改为新图标的方法。 Ok so, first create a member variable and get a reference to the menu item in onCreateOptionsMenu(). 好的,首先创建一个成员变量并获取onCreateOptionsMenu()中菜单项的引用。

Then when you click the item set the item to a new drawable (of your colour) 然后,当您单击该项目时,将项目设置为新的drawable(您的颜色)

MenuItem mMenuItem;

.....

menu.add("Map").setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM  |     MenuItem.SHOW_AS_ACTION_WITH_TEXT);
mMenuItem = menu.getItem(0); 


......
mMenuItem.setIcon(android.R.drawable.ic_menu_set_as);

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM