Search code examples
androidswipenavigation-drawer

How to detect that Navigation Drawer has been opened with an edge swipe (and not home icon)?


I am using a Navigation Drawer in my Android app.

As this is a pattern that I find really hard to discover, my plan was to add a little message at the bottom of the screen until the user finally discover it and succesfully opened it with a swipe.

I know that I could use:

public void onDrawerOpened(View drawerView) {
    // Stop telling the user, he know how it works
}

But this action is also triggered when opening it with the upper left button in the ActionBar.

Any suggestion to detect a succesfull swipe would be warmly welcome.


Solution

  • You need to listen to the state change callback:

            @Override
            public void onDrawerStateChanged(int newState) {                
                if (newState == DrawerLayout.STATE_DRAGGING) {
                    Log.v(TAG, "Drawer opened by dragging");
                }
            }
    

    This state only occurs when user drags the drawer into view. Tapping on home icon does not induce this - which is exactly what you want.