My navigation drawer keeps showing the last selected item.Is there any way to remove it.I want that if the user is at Home page, the navigation drawer items should be non-highlighted.
I have tried
drawer.setSelected(false);
in onResume(). But it doesn't help.
Please refer the attached screenshot, it will help understand.
In addition to the above solutions, if group element in your drawer_view.xml file includes the below attribute,
android:checkableBehavior="single"
as shown in the below example :
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single" >
<item
... />
<item
... />
</group>
</menu>
none of the above solution works. So be sure that you do not use that attribute if you do not want that highlight feature.
I use
@Override
protected void onResume() {
super.onResume();
for (int i = 0; i < navigationView.getMenu().size(); i++) {
navigationView.getMenu().getItem(i).setChecked(false);
}
}
if did not work, also add:
itemOfMenu.setChecked(false);
to the end of onNavigationItemSelected
override.
Use the code below:
navigationView.getMenu().getItem(0).setChecked(false);
Call this method after you call setNavDrawer();
The getItem(int index)
method gets the MenuItem
then you can call the setChecked(true);
on that MenuItem
, all you are left to do is to find out which element index does the default have, and replace the 0 with that index.
You can select (highlight) the item by calling:
onNavigationItemSelected(navigationView.getMenu().getItem(0));
Note: For nexus 4, support library revision 24.0.0. I recommend use
navigationView.setCheckedItem(id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With