androidmaterialdrawer

Material Drawer opens automatically as activity starts


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


Solution

  • 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);
        }