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?
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.
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;
To disable the DrawerLayout gesture recognition use:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
Then, to enable right to left swipe, check this resource: http://android-journey.blogspot.com/2010/01/android-gestures.html
Look like I found bug. For example if set:
android:layout_gravity="right"
or
android:layout_gravity="left"
for drawer content and use .setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
all will be fine.
But in case when android:layout_gravity="left|center_vertical"
or something like it LOCK_MODE_LOCKED_CLOSED
will not work.
The LOCK_MODE_LOCKED_CLOSED
nowadays completely prevents the nav menu from showing, even via the hamburger menu (which may be unwanted). The following worked for me: https://mcmap.net/q/118547/-disable-the-swipe-gesture-that-opens-the-navigation-drawer-in-android
This worked for me:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
You can expand the drawer by tapping the Hamburger icon or button from which you have to trigger. However, left-to-right swipe is no longer triggered.
© 2022 - 2024 — McMap. All rights reserved.