Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable gesture listener on DrawerLayout

How can I disable the gesture recognition for the DrawerLayout? (swipe left to right) and only accept the close gesture (right to left) and open the drawer just with the home button?

like image 912
Rodrigo Amaro Reveco Avatar asked Jun 10 '13 14:06

Rodrigo Amaro Reveco


People also ask

How do I turn off swipe gestures on Android?

Tap the gear icon next to “Gesture Navigation.” Note: The corner swipe gesture for Google Assistant is only available if you use gesture navigation. You don't have to turn it off if you use three-button navigation. Simply toggle the switch off for “Swipe to Invoke Assistant.”

What is DrawerLayout?

DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.


2 Answers

This worked for me:

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); 

You can expand the drawer by tapping the Home button, and can use right-to-left swipe gesture to dismiss it. However, left-to-right swipe is no longer triggered.

like image 100
Thuy Trinh Avatar answered Sep 29 '22 06:09

Thuy Trinh


For setDrawerLockMode(), this is in the code but not on the Android developer docs:

/**  * The drawer is unlocked.  */ public static final int LOCK_MODE_UNLOCKED = 0;  /**  * The drawer is locked closed. The user may not open it, though  * the app may open it programmatically.  */ public static final int LOCK_MODE_LOCKED_CLOSED = 1;  /**  * The drawer is locked open. The user may not close it, though the app  * may close it programmatically.  */ public static final int LOCK_MODE_LOCKED_OPEN = 2; 
like image 43
greg7gkb Avatar answered Sep 29 '22 06:09

greg7gkb