Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if navigation drawer is open?

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!

like image 698
Chinmay Dabke Avatar asked Feb 07 '14 17:02

Chinmay Dabke


People also ask

How do you check if drawer is open react native?

If you would like to determine if drawer is open or closed, you can do the following: import { useDrawerStatus } from '@react-navigation/drawer'; // ...

How does navigation drawer work?

The navigation drawer slides in from the left and contains the navigation destinations for the app. The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar.

Which piece of code is used to close the navigation drawer?

Use closeDrawer() method to close the drawer and start your other activity on the listener of drawer.


2 Answers

Assuming you have defined a drawerlayout in xml:

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); ... if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) {   //drawer is open } 
like image 69
Neoh Avatar answered Sep 22 '22 18:09

Neoh


 mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);     mDrawerToggle = new ActionBarDrawerToggle(             this,                  /* host Activity */             mDrawerLayout,         /* DrawerLayout object */             R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */             R.string.drawer_open,  /* "open drawer" description */             R.string.drawer_close  /* "close drawer" description */             ) {          /** Called when a drawer has settled in a completely closed state. */         public void onDrawerClosed(View view) {             super.onDrawerClosed(view);             getActionBar().setTitle(mTitle);         }          /** Called when a drawer has settled in a completely open state. */         public void onDrawerOpened(View drawerView) {             super.onDrawerOpened(drawerView);             getActionBar().setTitle(mDrawerTitle);         }     };      // Set the drawer toggle as the DrawerListener     mDrawerLayout.setDrawerListener(mDrawerToggle); 

That listener use:)

like image 28
ShakeJ Avatar answered Sep 19 '22 18:09

ShakeJ