I am able to navigate from Activity1 to Activity2 via my navigation drawer.
But upon pressing the back button at activity2, the option remains highlighted.
My Code in activity1 is as followed
public boolean onNavigationItemSelected(MenuItem Item) { int id = item.getItemId(); if(id == R.id.activity2) { Intent goPage2 = new Intent(activity1.this, activity2.class); startActivity(goPage2); } }
there is no code in activity 2.
May I know what do I do to remove the highlight?
我发现如果不需要使用突出显示功能,只需在onNavigationItemSelected的末尾返回false即可。
} else if (id == R.id.nav_share) { } else if (id == R.id.nav_send) { } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return false; }
要取消选中项目单击,必须传递false
选中的项目:
public boolean onNavigationItemSelected(MenuItem Item) //will consider to keep this in lower case - item { int id = item.getItemId(); if(id == R.id.activity2) { Intent goPage2 = new Intent(activity1.this, activity2.class); startActivity(goPage2); Item.setChecked(false); //pass false to uncheck } }