在DrawerLayout上禁用手势监听器

Rod*_*eco 62 android drawerlayout

如何禁用DrawerLayout的手势识别?(从左向右滑动)并且只接受关闭手势(从右到左)并使用主页按钮打开抽屉?

Thu*_*inh 155

这对我有用:

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Run Code Online (Sandbox Code Playgroud)

您可以通过点按"主页"按钮展开抽屉,也可以使用从右向左滑动手势来关闭它.但是,不再触发从左向右滑动.

  • 要解锁它,请使用mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); (21认同)
  • 这在我的情况下不起作用,即使我使用上述解决方案设置抽屉布局,我总是在滑动手势上得到一个抽屉. (7认同)

gre*_*gkb 21

对于setDrawerLockMode(),这是在代码中,而不是Android开发人员文档:

/**
 * 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;
Run Code Online (Sandbox Code Playgroud)