I want to hide NavigationView
before go to new activity . In this time in my app Navigation Drawer not hiding properly yet start new activity . So I want to hide navigation properly then go to new activity .And I am not using number of fragment with activity. I am using total activity with navigation drawer.
Asked
Active
Viewed 311 times
0

N J
- 27,217
- 13
- 76
- 96

Satendra Baghel
- 89
- 6
2 Answers
0
Use
mDrawerLayout.closeDrawers();
if you want to close drawer and then launch another Activity
add delay using Handler
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//launch activity here
}
},TIME_IN_MILLI_SEC)

N J
- 27,217
- 13
- 76
- 96
0
You can try closing your drawer when a item is selected:
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
menuItem.setChecked(true);
//saving the id of the item selected
itemSelected = menuItem.getItemId();
mDrawerLayout.closeDrawers();
return true;
}
});
Then you can use a DrawerLayout.DrawerListener
. On the onDrawerClosed
you can start your Activity
@Override
public void onDrawerClosed(View drawerView) {
if (itemSelected >= 0) {
Class activityClass = null;
switch (itemSelected) {
case R.id.itemId:
activityClass = MyActivity.class;
break;
//same for any other item
}
if (activityClass != null) {
Intent intent = new Intent(this, activityClass);
startActivity(intent);
finish();
}
}
}

hashiCode
- 489
- 8
- 17