10

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);
RedLeader
  • 657
  • 1
  • 15
  • 28

2 Answers2

3

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?

Community
  • 1
  • 1
sastraxi
  • 1,330
  • 11
  • 21
0

You have to create a custom layout for your action containing a checkbox. See my answer here.

Community
  • 1
  • 1
Timmmm
  • 88,195
  • 71
  • 364
  • 509