-2

When I use Material Drawer, as soon as a new activity starts, drawer is being displayed automatically, but I want that it starts hidden, so I have to use function drawer.closeDrawer() in the method onResume of activity, as described below:

@Override
protected void onResume() {
    super.onResume();

    drawer.closeDrawer();
}

Is this the correct way to hidden the drawer when activity starts or restarts, or there is a property to be set for this purpose in the drawer?

Thank you,
Alexandre Bianchi

2 Answers2

1

There are different cases why the drawer may opens after the application starts.

Either you define withShowDrawerOnFirstLaunch, this should be removed or set to false, if you don't want this behavior. https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/DrawerBuilder.java#L1188

It could also be that you open the drawer via the Drawer's API. So make sure you don't call openDrawer programtically https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L125

The Drawer comes also with a method to close the drawer. Just call closeDrawer https://github.com/mikepenz/MaterialDrawer/blob/develop/library/src/main/java/com/mikepenz/materialdrawer/Drawer.java#L134

mikepenz
  • 12,708
  • 14
  • 77
  • 117
0

Put this code in oncreate and it will check the drawer is open or not...if its open it will close the drawer

    DrawerLayout layout = (DrawerLayout) findViewById(R.id.drawer_layout);
         if (layout.isDrawerOpen(GravityCompat.START)) {
             layout.closeDrawer(GravityCompat.START);
    }
Rajakumar
  • 907
  • 1
  • 7
  • 17