Navigation Drawer Highlight Not Working Properly
When I select an option in the drawer and change to another one, the highlighting doesn't change. I mean, the first selected option will remain highlighted and the second one won't
Solution 1:
navigationView.setCheckedItem(id);
This method was introduced in API 23.0.0
You should check out performIdentifierAction as well. It should select the specified item and execute the action associated with it.
Solution 2:
There could be many ways to solve this problem.
First Make navigationView
public.
Then first clear all the checked clearChecked()
and then set the checked navigationView.getMenu().findItem(navId).setChecked(true);
Find below changes to your code.
private NavigationView navigationView;
@OverridepublicbooleanonNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
navId = item.getItemId();
clearChecked();
navigationView.getMenu().findItem(navId).setChecked(true);
if (navId == R.id.nav_home) {
// Handle the action
} elseif (navId == R.id.nav_my_profile){
Intentintent=newIntent(this, MyProfile.class);
startActivity(intent);
} elseif (navId == R.id.nav_buy_puntos) {
} elseif (navId == R.id.nav_settings){
} elseif (navId == R.id.nav_share) {
} elseif (navId == R.id.nav_feedback) {
Intentintent=newIntent(this, FeedbackActivity.class);
startActivity(intent);
} elseif (navId == R.id.nav_help) {
} elseif (navId == R.id.nav_log_out){
finish();
BaseActivity.hideProgressDialog();
}
DrawerLayoutdrawer= (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
returntrue;
}
privatevoidclearChecked() {
intsize= navigationView.getMenu().size();
for (inti=0; i < size; i++) {
navigationView.getMenu().getItem(i).setChecked(false);
}
}
Post a Comment for "Navigation Drawer Highlight Not Working Properly"