disable the swipe gesture that opens the navigation drawer in android
You should use:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
It worked for me, the swipe to open the drawer was disabled.
If it still won't work, check out the answer provided here.
Disable swipe for open drawer but NOT for closing
I found a workaround to achieve what I want:
Initialy I set the drawerMode to CLOSED. After opening it e.g. via a button, I UNLOCK the drawer to enable the gesture for closing again. After the drawer has been closed the Lock for opening will be reactivated. For this I'm using the Interface of the ActionBarDrawerToggle
mDrawerToggle = new ActionBarDrawerToggle(
getActivity(), /* host Activity */
mDrawerLayout, /* DrawerLayout object */
R.string.navigation_drawer_open, /* "open drawer" description for accessibility */
R.string.navigation_drawer_close /* "close drawer" description for accessibility */
)
{
@Override
public void onDrawerClosed(View drawerView)
{
super.onDrawerClosed(drawerView);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
@Override
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
};
I tried to overide the drawerlayout or parts of it, but it would be a hell of work to get what I want.
I hope this solution is helpfull to others.
Disable swipe gesture (navigation drawer) from specific fragment
I use this code & it works for me.
public void closeDrag()
{
try
{
mDragger = drawerLayout.getClass().getDeclaredField("mLeftDragger");
}
catch (NoSuchFieldException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
mDragger.setAccessible(true);
try
{
draggerObj = (ViewDragHelper) mDragger.get(drawerLayout);
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
mEdgeSize = draggerObj.getClass().getDeclaredField("mEdgeSize");
}
catch (NoSuchFieldException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
mEdgeSize.setAccessible(true);
try
{
edge = mEdgeSize.getInt(draggerObj);
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
try
{
mEdgeSize.setInt(draggerObj, edge * 0);
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Note: it will allow to open/close drawer from Actionbar button but will disable finger swipe.
Disable swipe gesture from opening the navigation drawer using react-navigation
You can use the drawerLockMode
in the screen navigation options using the option locked-open
locked-open: the drawer will stay opened and not respond to gestures. The drawer may still be opened and closed programmatically
Other options can be viewed here
static navigationOptions = {
drawerLockMode: 'locked-open',
}
Navigation drawer - disable swipe
You can use
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
to lock your DrawerLayout
so it won't be able to open with gestures. And unlock it with:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
Here you can find more info about DrawerLayout
: Android API - DrawerLayout
Disable gesture listener on DrawerLayout
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.
Related Topics
Two Main Activities in Androidmanifest.Xml
Resources and Layout Direction Rendered Incorrectly Only on Android 8.0 and Above
Parsing Date/Time to Localtimezone
Sqlitedatabase Close() Function Causing Nullpointerexception When Multiple Threads
Find the Physical Address of Exception Vector Table from Kernel Module
Widgets Don't Respond When Re-Added Through Code
Read Logs from All Apps on Android from Within an App for Android 4.2+
How to Apply Primary Key on the Text Fields in Android Database
How to Check If User Is Logged in with Fb Sdk 4.0 for Android
Android: How to Return Async JSONobject from Method Using Volley
How to Create Drawable from Resource
Android M Write to Sd Card - Permission Denied
When Do I Use Setstate in Flutter
Android How to Identify Item in Listview with Checkbox
I Want Show Notification at 8:00 Am Everyday
How to Set The Font Style to Bold, Italic and Underlined in an Android Textview