Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hitesh-dhamshaniya/e709c7e4a9ba38363d1647aa46b92cd9 to your computer and use it in GitHub Desktop.
Save hitesh-dhamshaniya/e709c7e4a9ba38363d1647aa46b92cd9 to your computer and use it in GitHub Desktop.
How to set shared checkable behavior across all groups in NavigationView?
Here's the solution.
Step 1: Remove
android:checkableBehavior="single"
from both groups.
Step 2: Add the following logic to the listener:
mUiNavigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
menuItem.setCheckable(true);
menuItem.setChecked(true);
if (mPreviousMenuItem != null) {
mPreviousMenuItem.setChecked(false);
}
mPreviousMenuItem = menuItem;
//...
changeCurrentFragment(...);
return true;
}
});
Note: instead of calling menuItem.setCheckable(true) you can set android:checkable="true" for each item in XML.
http://stackoverflow.com/questions/30766919/how-to-set-shared-checkable-behavior-across-all-groups-in-navigationview
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment