简体   繁体   中英

ActionBar change color of menuitem button when pressed

How to change color of menuitem button when it pressed. I use SherlockActionBar but when it pressed it changes color to one that it not really good for my design. 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. I can change the drawable, but background will still change it`s color to ugly one.

You can change the background by setting the actionBarItemBackground attribute in your theme. This should be a state-list drawable which reflects states such as pressed and focused.

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().

Then when you click the item set the item to a new drawable (of your colour)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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