When the app is run the first drawer presented is correct ie; comes with only one visible option item. This option when selected activates an activity that is normally executed but at the end of its execution the other options are not visible.
drawer_layout
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single"
android:id="@+id/drawer_register" android:visible="true">
<item
android:id="@+id/nav_drawer_register"
android:title="@string/drawer_register"
android:icon="@drawable/ic_person_add_black_24dp" />
</group>
<item android:title="@string/drawer_app"
android:id="@+id/drawer_app" android:visible="false">
<menu>
<item
android:id="@+id/nav_drawer_app_login"
android:title="@string/drawer_app_login"
android:icon="@drawable/ic_fingerprint_black_24dp" />
<item
android:id="@+id/nav_drawer_app_logout"
android:title="@string/drawer_app_logout"
android:icon="@drawable/ic_exit_to_app_black_24dp" />
</menu>
</item>
</menu>
Main Activity
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar,
R.string.main_navigation_drawer_open,
R.string.main_navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView)
findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_teste);
navigationView.setNavigationItemSelectedListener(this);
drawer.openDrawer(GravityCompat.START);
Listener
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
// ================================================================================== //
// FUNCTION REGISTER ME //
// ================================================================================== //
if (id == R.id.nav_drawer_register) {
Toast toast =
Toast.makeText(this,
R.string.device_register_warning, Toast.LENGTH_SHORT);
toast.show();
userType = "0";
Intent intent = new Intent(RegisterStatusListActivity.ACTION_REG_STATUS_DATA);
intent.addCategory(RegisterStatusListActivity.CATEGORY_REG_STATUS_DATA);
intent.putExtra(RegisterStatusListActivity.EXTRA_REG_TYPE, userType);
startActivity(intent);
setAllVisible(true); // <===== ATIVA MUDANÇA DE VISIBILIDADE
return true;
} else
setAllVisible
public void setAllVisible(boolean visible){
NavigationView navigationView = (NavigationView)
findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_teste);
toggleVisibility(navigationView.getMenu(), R.id.drawer_app, visible);
}
private void toggleVisibility(Menu menu, @IdRes int id, boolean visible){
menu.findItem(id).setVisible(visible);
}
SUMMARY
At the end of the activity that processed the first selected option, the drawer continues with the other invisible options. Is there a solution?