NavigationView set selected item as checked

TareK Khoury picture TareK Khoury · Aug 6, 2015 · Viewed 8k times · Source

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);

Answer

Arlind picture Arlind · Aug 6, 2015

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.