I have a working Navigation Drawer and having some issues with menuItem.setChecked(true);
when using groups and headers within the menu. It\'s not highlighting menu
Try this:
private int selectedItem = 0;
private void setSelectedItem(MenuItem menuItem, int position) {
mNavigationView.getMenu().getItem(selectedItem).setChecked(false);
mNavigationView.getMenu().getItem(position).setChecked(true);
if (menuItem.getGroupId() == R.id.group_2) {
mNavigationView.getMenu().setGroupCheckable(R.id.group_1, false, true);
mNavigationView.getMenu().setGroupCheckable(R.id.group_2, true, true);
} else {
mNavigationView.getMenu().setGroupCheckable(R.id.group_1, true, true);
mNavigationView.getMenu().setGroupCheckable(R.id.group_2, false, true);
}
//Update highlighted item in the navigation menu
menuItem.setChecked(true);
selectedItem = position;
}