I know it's possible to highlight a navigation view item by calling setCheckedItem()
or return true value in onNavigationItemSelected
to display the item as the selected item, but How can I uncheck the checked items of a navigation view?

- 8,381
- 4
- 46
- 63
12 Answers
This will uncheck the items:
int size = mNavigationView.getMenu().size();
for (int i = 0; i < size; i++) {
mNavigationView.getMenu().getItem(i).setCheckable(false);
}

- 6,975
- 3
- 32
- 31
-
i don't know after using your code it's giving me a blank space! – phpdroid Sep 14 '17 at 17:13
-
6in my case, after using your technique, i got checked the last item and i can't resolve it. please help me... – takmilul Dec 26 '17 at 07:14
-
@takmilul make sure you use `setChecked(false);` not `true` – arsent Dec 26 '17 at 18:26
-
with the code proposed the last item get selected. I solved the problem by replacing `setChecked(false)` with `setCheckable(false)` – Roberto Dec 28 '17 at 17:13
-
`setCheckable(false)` combined with `setChecked(false)` for each item worked in my case. – kkaun Sep 01 '18 at 11:11
-
Even though it **does** uncheck all items, it prevents the items from being checked in the future. – Thorsten Dittmar Sep 19 '19 at 08:21
-
use setChecked(false) – Yogesh Nikam Patil Jan 14 '20 at 06:14
I saw @arsent solution and gave it a try, and it will indeed do what you want, which is to unselect all the items... but, I was having an issue in the following scenario:
- Select menu item 1 (using
NavigationView#setCheckedItem
) - Unselect all the items as per @arsent's solution
- Select menu item 1 again (using
NavigationView#setCheckedItem
)
In this scenario, item 1 will not be marked as checked. That's because internally the navigation view keeps track of the previously selected item set in step 1, which doesn't change in step 2, and it just skips step 3 because the previously selected item is the same as the one we're selecting now.
My suggestion (and an alternative solution) to avoid this is just having a dummy invisible item and use NavigationView#setCheckedItem
to select that item whenever you want to unselect all, like so
<item
android:id="@+id/menu_none"
android:title=""
android:visible="false"/>
To unselect all just do
mNavigationView.setCheckedItem(R.id.menu_none);

- 4,055
- 1
- 26
- 29
-
4I found I also had to make that menu item `checkable="true"` for it to work, but once I did that, it's perfect! – AtkinsSJ Aug 09 '18 at 17:54
-
1
-
Such a shame that similar feature isn't built in the SDK and we must hack on it – Bartek Pacia Mar 09 '19 at 11:22
-
1
To uncheck all MenuItems
including SubMenu
items you have to use recursion -
private void unCheckAllMenuItems(@NonNull final Menu menu) {
int size = menu.size();
for (int i = 0; i < size; i++) {
final MenuItem item = menu.getItem(i);
if(item.hasSubMenu()) {
// Un check sub menu items
unCheckAllMenuItems(item.getSubMenu());
} else {
item.setChecked(false);
}
}
}
Call above method for unchecking all items, like below -
unCheckAllMenuItems(navigationView.getMenu());

- 10,457
- 4
- 35
- 55
just make your items non checkable like so
<item
android:id="@+id/profile_item"
android:checkable="false"
android:title="@string/profile"/>

- 1,545
- 2
- 11
- 20
Quoting @Codeversed, there is "no need to loop menu items with added overhead!". But, there is no need to create multiple groups (in this case he is creating the @+id/grp1
and @+id/grp2
) to uncheck a previous checked item.
You can simple add a single group for all elements with the android:checkableBehavior
, like this:
<group android:checkableBehavior="single">
<item
android:id="@+id/id1"
android:checked="true"
android:icon="@drawable/drawable1"
android:title="@string/string1" />
<item
android:id="@+id/id2"
android:icon="@drawable/drawable2"
android:title="@string/string2" />
</group>

- 5,329
- 5
- 32
- 42
Joao's solutions didn't not work for me as totally expected. This would lead to a blank space from unchecked Item View on my Navigation.
Just make sure to set the view as gone:
<item
android:id="@+id/your_menu_item_id_to_hide"
android:title=""
android:visible="false"/>
bottomNavigationView.getMenu().findItem(R.id.your_menu_item_id_to_hide).setChecked(true);
bottomNavigationView.findViewById(R.id.your_menu_item_id_to_hide).setVisibility(View.GONE);
Arsent solution is not necessary in this case.

- 3,293
- 7
- 47
- 77
-
I had this same problem and I fixed it, but I can't remember right now how. Double check xml parameters on your layout files – Victor Oliveira Feb 10 '17 at 13:16
-
ah that's a bottom navigation view, which is kind of recent. I've never tried my solution with that component, but good to know you managed to tweak it. – Joao Sousa Mar 29 '17 at 14:33
All you need to do is surround your groups like this:
<group>
<group
android:id="@+id/grp1">
<item
android:id="@+id/nav_profile"
android:icon="@drawable/ic_account_circle_24dp"
android:title="@string/profile" />
</group>
<group
android:id="@+id/grp2">
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings_24dp"
android:title="@string/settings" />
<item
android:id="@+id/nav_help"
android:icon="@drawable/topic_help"
android:title="@string/help_feedback" />
</group>
</group>
No need to loop menu items with added overhead!

- 9,287
- 3
- 43
- 42
I guess someone like me use those methods just like this
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_today:
break;
case R.id.nav_calendar:
navigationView.getMenu().performIdentifierAction(R.id.nav_today, 0);
navigationView.getMenu().getItem(0).setChecked(true);//or
navigationView.setCheckedItem(R.id.nav_today);//or
drawerLayout.closeDrawers();
break;
}
return true;
}
Trying to check R.id.nav_today
after you clicked on R.id.nav_calendar
, (btw: checkableBehavior="single"
), unfortunately it will not work.
That is because after your code navigationView.setCheckedItem(R.id.nav_today)
be called then the R.id.nav_today
will be checked immediately, but after this, your click on R.id.nav_calendar
will check itself.
That is why whatever methods you use seem never work at all. It is work, but be override immediately.

- 9,929
- 4
- 40
- 61

- 404
- 4
- 5
To uncheck it inside NavigationItemSelectedListener
I had to use post (to UI thread):
App.getHandler().post(() -> menuItem.setChecked(false));
Full example:
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(
menuItem -> {
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
switch (menuItem.getItemId()) {
...
}
App.getHandler().post(() -> menuItem.setChecked(false));
return true;
});
p.s. in my case App.getHandler()
returns Handler
instance for UI Thread Lopper

- 8,146
- 7
- 57
- 139
I had to use a combination of all the solutions mentioned here. In my case, I want to open an URL Intent when the Item is clicked (open a Browser). The clicked item should get unchecked after the click and reset to the item before. Important is to understand, that you cannot uncheck an item during the click listener event, since the checked state will be handled afterwards. So this is my solution in Kotlin:
val item = navigationView.menu.findItem(R.id.menu_item)
item.setOnMenuItemClickListener {
val oldItem = navigationView.checkedItem
rootView.postDelayed({ // you can use here any View to post a Runnable with a delay
navigationView.setCheckedItem(oldItem?.itemId ?: R.id.default_item)
}, 500)
browseURL("https://www.example.com")
true
}
I use a Navigation Drawer in combination with the Jetpack Navigation.

- 5,630
- 1
- 43
- 53
i combine @arsent and @Rahul answers and write this code:
private void NavigationView_NavigationItemSelected(object sender, NavigationView.NavigationItemSelectedEventArgs e)
{
var size = navigationView.Menu.Size();
for (int i = 0; i < size; i++)
{
var item= navigationView.Menu.GetItem(i).SetChecked(false);
if (item.HasSubMenu)
{
for (int j = 0; j < item.SubMenu.Size(); j++)
{
item.SubMenu.GetItem(j).SetChecked(false);
}
}
}
e.MenuItem.SetChecked(true);
drawerLayout.CloseDrawers();
}
above code is for xamarin c# and work,but u can easily convert to java

- 649
- 1
- 10
- 27
@arsent's answer is correct but setCheckable(false) uncheck all items, it prevents the items from being checked in the future.
Just use setChecked(false)
int size = mNavigationView.getMenu().size();
for (int i = 0; i < size; i++) {
mNavigationView.getMenu().getItem(i).setChecked(false);
}

- 1,192
- 13
- 18