1

How can I disable single finger menu drawer open (swipe left to right) for the DrawerLayout, however allow the menu drawer to open with two fingers swipe?

Single finger swipe to not open the drawer menu, but child views to be able to process touch events. Only the menu open functionality is to be forbidden for single finger swipe.

An update: I have read this very useful topic: (Android: Difference between onInterceptTouchEvent and dispatchTouchEvent?) .

So I've decided to overrrite method onInterceptTouchEvent
public boolean onInterceptTouchEvent(MotionEvent arg) { if (arg.getPointerCount() < 2 && !this.isDrawerOpen(this.listView)) { return true; } else { return super.onInterceptTouchEvent(arg); } }

However obviously it does not send touch events to children views. I think I have to use LOCK_MODE_LOCKED_CLOSED in order to control enable/disable of drawer. I will post that solution here later.

Community
  • 1
  • 1
Lyubo Gos
  • 19
  • 6

1 Answers1

0

I think this is the solution using LOCK_MODE for this task, if anyone has something better, please share:

@Override
public boolean onInterceptTouchEvent(MotionEvent arg) {
    if (arg.getPointerCount() < 2) {
        if (!this.isDrawerOpen(this.listView)) {
            // The drawer is locked closed. The user may not open it.
            this.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    } else {
        // The drawer is unlocked.
        this.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    }

    return super.onInterceptTouchEvent(arg);
}
Lyubo Gos
  • 19
  • 6