Disable DrawerLayout swipe gestures for opening AND closing menu

Viewed 338

The drawer menu is interfering with my viewpager's swipe gestures. I looked at previous posts and set the drawerLayout to mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); however this only works when trying to swipe to open the menu, if the menu is open it still allows swipe gestures to close the menu.

Is there a way to outright disable swipe gestures for the entire view? That way, the only way a user can open the menu is by tapping on the burger menu icon or can close is by tapping on the "X" button inside the menu, also swiping while the drawer menu is open shouldn't affect the viewpager.

2 Answers

I figured out a solution for this.

I set up a boolean isDrawerOpen variable in the application class that listens for when the drawer is open or closed, then overrode the onTouch events in my viewpager fragment to disable touch events whenever the isDrawerOpen == true

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) is working fine but when the drawer is opened, you can check if the drawer is opened or not when tapping the button.

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
   mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
}
Related