NavigationView 将所选项目设置为已选中

NavigationView set selected item as checked

我正在使用支持库中的 NavigationView。我有一个 BaseActivity Activity A 和 B 延伸自。

默认情况下,应用程序以 Activity A 开始。当用户单击抽屉菜单项时,我开始 activity B.

启动后activity B.如何设置对应的菜单项高亮为勾选?

提前致谢

更新:

现在有了支持库的最新更新,您可以:

mDrawer.setCheckedItem(R.id.drawer_profile);

使用下面的代码:

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

调用setNavDrawer()后调用该方法;

getItem(int index)方法获取到MenuItem,然后调用setChecked(true);在该 MenuItem 上,您剩下要做的就是找出默认主页有哪个元素索引,并将 0 替换为该索引。