I have a small problem with navigation drawer. I want to have nothing "checked" after return to main activity, here is more about my problem:
When I am starting an activity, I have menu like that:
That is good :) When I click "User profil" or other menu item I am opening new activity. I don't have any menu in this "new activity", only return button, so I am returning to main activity. And here is a problem, when I return to main activity and I open navigation drawer, it is looking like:
What I have to do to uncheck this menu item that I previous open?
//EDIT Code of Navigation Drawer:
mToolbar = findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
ActionBar actionbar = this.getSupportActionBar();
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setHomeAsUpIndicator(R.drawable.ic_menu_black_24dp);
mDrawerLayout = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
// close drawer when item is tapped
mDrawerLayout.closeDrawers();
switch (menuItem.getItemId()) {
case android.R.id.home:
mDrawerLayout.openDrawer(GravityCompat.START);
return true;
case R.id.action_user:
//Save info about clicked menu item to open correct activity when "onDrawerClosed" listener will be call
choseIntentFromDrawerLayout= EventContract.EventEntry.MENU_USER_PROFIL;
return true;
case R.id.action_settings:
choseIntentFromDrawerLayout=EventContract.EventEntry.MENU_SETTINGS;
return true;
case R.id.action_about:
choseIntentFromDrawerLayout= EventContract.EventEntry.MENU_ABOUT;
return true;
case R.id.action_log_out:
choseIntentFromDrawerLayout= EventContract.EventEntry.MENU_LOG_OUT;
return true;
default:
choseIntentFromDrawerLayout= EventContract.EventEntry.MENU_NOTHING;
}
//UNCHECK? - NO WORKING
if(menuItem.isChecked()){
menuItem.setChecked(false);
}
return true;
}
});
mDrawerLayout.addDrawerListener(
new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Respond when the drawer's position changes
}
@Override
public void onDrawerOpened(View drawerView) {
// Respond when the drawer is opened
choseIntentFromDrawerLayout= EventContract.EventEntry.MENU_NOTHING;
}
@Override
public void onDrawerClosed(View drawerView) {
// Respond when the drawer is closed
switch (choseIntentFromDrawerLayout) {
case EventContract.EventEntry.MENU_USER_PROFIL:
Intent intentUser = new Intent(CatalogActivity.this,UserActivity.class);
mExtraInfoHelp.putWindsurferToIntent(intentUser,mWindsurfer,getApplicationContext());
startActivity(intentUser);
break;
case EventContract.EventEntry.MENU_SETTINGS:
Intent intentSettings = new Intent(CatalogActivity.this,SettingsActivity.class);
startActivity(intentSettings);
break;
case EventContract.EventEntry.MENU_ABOUT:
Intent intentAbout = new Intent(CatalogActivity.this,AboutActivity.class);
startActivity(intentAbout);
break;
case EventContract.EventEntry.MENU_LOG_OUT:
AuthUI.getInstance().signOut(CatalogActivity.this);
break;
case EventContract.EventEntry.MENU_NOTHING:
break;
}
}
@Override
public void onDrawerStateChanged(int newState) {
// Respond when the drawer motion state changes
}
}
);