[FIXED] Can I listen to when the Navigation drawer is opened or closed (e.g: listener like button onclick)?


I want to call a method when the Navigation Drawer opens and closes. How can I listen to it (like a button’s onclick listener)?

I know I can check (mDrawer.isDrawerOpen(Gravity.LEFT)) or ((mDrawer.isDrawerClose(Gravity.LEFT))) .

Thank you.


Yeah there are four abstract methods that you can use as listeners

public abstract void onDrawerClosed (View drawerView)
public abstract void onDrawerOpened (View drawerView)
public abstract void onDrawerSlide (View drawerView, float slideOffset)
public abstract void onDrawerStateChanged (int newState)

can be used like this

ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
        R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
    public void onDrawerClosed(View view) {
        // Do whatever you want here
    public void onDrawerOpened(View drawerView) {
        // Do whatever you want here

copied from http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.DrawerListener.html

setDrawerListener method was deprecated in API level 24.1.0. so use addDrawerListener()

Answered By – Rahul

Answer Checked By – Mildred Charles (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published