问题
I currently am programming for API 10 and above. I created a menu and was looking to implement the method Menu.setGroupCheckable(id, checkable, exclusive). Below is my code. From the documentation I was expecting a check mark over the selected item out of the group and the other ones to be disabled. However, this is not the case.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, 1, 0, "I1").setIcon(R.drawable.ic_launcher);
menu.add(0, 2, 1, "I2");
menu.add(0,3,2,"I3");
menu.add(1, 4, 3, "I4");
menu.add(1, 5, 4, "I5");
menu.add(1,6,5,"I6");
menu.setGroupCheckable(1, true, true);
return true;
}
Android documentation link: http://developer.android.com/reference/android/view/Menu.html
回答1:
Android Menu: Two single-checkable groups in the same menu
http://www.brighthub.com/mobile/google-android/articles/28673.aspx
http://www.mysamplecode.com/2011/07/android-options-menu-submenu-group.html
http://www.itcsolutions.eu/2011/09/26/android-tutorial-how-to-add-a-menu-programmatic-vs-declarative-solution/
These links may help you!!!
回答2:
use Updated lib
compile 'com.android.support:appcompat-v7:23.1.0' compile 'com.android.support:design:23.1.0'
来源:https://stackoverflow.com/questions/10720427/android-menu-group-checkable