I have the following menu layout in my Android app:
You can create a checkable menu item by setting the actionViewClass
to a checkable widget like android.widget.CheckBox
res/menu/menu_with_checkable_menu_item.xml
And you can can even style it to be a checkable star if you set actionLayout
to a layout with a styled android.widget.CheckBox
res/layout /action_layout_styled_checkbox.xml
res/menu/menu_with_checkable_star_menu_item.xml
To set the value
menuItem.setChecked(true/false);
To get the value
menuItem.isChecked()
Cast MenuItem to CheckBox
CheckBox checkBox= (CheckBox) menuItem.getActionView();