Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActionBar setCheckable() not working

I'm trying to make one of the MenuItems on my Menu have a checkmark ability, but it doesn't seem to work. All other MenuItems are working, this one does too, except for the checkmark display. What am I doing wrong?

MenuItem actionPickMode = menu.add(0, 3, 0, "pickmode");
actionPickMode.setTitle("Pick Mode");
actionPickMode.setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT
                | MenuItem.SHOW_AS_ACTION_ALWAYS);
actionPickMode.setVisible(true);
actionPickMode.setCheckable(true);
like image 878
RedLeader Avatar asked Jul 18 '11 22:07

RedLeader


1 Answers

Looks like you're trying to add a checkmark to a MenuItem that is actually on the Action Bar. According to this question it isn't possible: Android action bar checkable menu item does not work/show properly?

What you can do is implement it yourself--when the item is clicked, use setIcon to change the drawable, and maintain the state of the toggle yourself. This question describes how you can get the built-in checkmark Drawables: How to access checkmark drawable in Android OS?

like image 126
sastraxi Avatar answered Sep 27 '22 02:09

sastraxi