How to detect if navigation drawer is open?

Chinmay Dabke picture Chinmay Dabke · Feb 7, 2014 · Viewed 65.9k times · Source

The title explains it all. All what I want to do is to know if the navigation drawer is open or not. I searched a lot on the net and found the method isDrawerOpen(int drawerGravity)but couldn't find a satisfactory answer which explains how to use it in a method. I would appreciate if anyone explains it to me.

Thanks in advance!

Answer

Neoh picture Neoh · Feb 7, 2014

Assuming you have defined a drawerlayout in xml:

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
...
if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
  //drawer is open
}