How to close navigation drawer when an item is pressed from it? How to close navigation drawer when an item is pressed from it? android android

How to close navigation drawer when an item is pressed from it?


Got it!

private DrawerLayout mDrawerLayout;mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);mDrawerLayout.closeDrawers();

Working perfectly fine.


For me this one worked -

mDrawerLayout.closeDrawer(Gravity.START, false);


DrawerLayout mDrawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout)closeDrawer(); // called when you want to closepublic void closeDrawer() {  if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {    mDrawerLayout.closeDrawer(GravityCompat.START);  }}