Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationView set selected item as checked [duplicate]

I am using NavigationView from the support library. I have a BaseActivity that Activity A and B extend from.

By default app starts with Activity A. When user clicks on a a drawer menu item, i start activity B.

After starting activity B. how can i set the menu item corresponding with it to be highlighted as checked?

Thanks in advance

UPDATE:

Now with the latest update to the support library, you can do:

mDrawer.setCheckedItem(R.id.drawer_profile);
like image 908
TareK Khoury Avatar asked Aug 06 '15 16:08

TareK Khoury


1 Answers

Use the code below:

navigationView.getMenu().getItem(0).setChecked(true);

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 left to do and find out is which element index does the home the default have, and replace the 0 with that index.

like image 113
Arlind Avatar answered Oct 20 '22 05:10

Arlind