Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 808
Waza_Be Avatar asked Jun 18 '13 20:06

Waza_Be


People also ask

How to show navigation drawer in Android?

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. The drawer icon is displayed on all top-level destinations that use a DrawerLayout.

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

Just add closeDrawer() inside onNavigationItemSelected() to close the drawer on selecting any item on Navigation Drawer.

Where is the navigation drawer on my phone?

The navigation drawer is a UI panel that shows your app's main navigation menu. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger from the left edge of the screen.


1 Answers

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.

like image 93
Sarang Avatar answered Sep 21 '22 18:09

Sarang