Reputation: 363
I have a DrawerLayout
that contains a list.
I want to disable the the swipe-close on it so the ways to close it would be clicking on the back button or clicking the inactive area of the drawer.
Is there a good practice implementing this behavior?
Upvotes: 0
Views: 1337
Reputation: 363
Aakash Goyal's answer have done half the trick:
setting the drawer lock mode with DrawerLayout.LOCK_MODE_LOCKED_CLOSED
Indeed disabled gestures exactly as I wanted. However on that case it was also disabling the Back button press to close the drawer.
So I've also added code for intercepting the back press and close the drawer:
mDrawerLayout.setOnKeyListener(new OnKeyListener()
{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if( keyCode == KeyEvent.KEYCODE_BACK )
{
if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT))
{
mDrawerLayout.closeDrawer(Gravity.RIGHT);
return true;
}
}
return false;
}
});
Also, I've changed the lock mode to unlocked when the drawer get closed - as I still want to allow it to open on swipe.
Upvotes: 1
Reputation: 1900
You can use setDrawerLockMode()
function of the Navigation Drawer with DrawerLayout.LOCK_MODE_LOCKED_CLOSED
as parameter to disable gestures
Upvotes: 1