I have an Activity with Navigation Drawer. if user device is table and orientation is landscape - I not need to close drawer by click on item in drawer:
if (!isTablet || context.getResources().getConfiguration().orientation==1) {
mDrawerLayout.closeDrawer(Gravity.START);
}
It work. But if user touch the screen outside opened drawer - drawer closing. Using DrawerLayout.LOCK_MODE_LOCKED_OPEN is unsuitable bacause I need to save drawer sliding functions. How to prevent closing Navigation drawer when user touch outside the drawer?
Please, help.
it very simple use your drawer instance to prevent
1. implement DrawerLayout.DrawerListener
2. add this single statement inside this method us
Simplified version of Noundla's answer which works for me. I wrote my custom Drawer which extends
DrawerLayout
and implementdispatchTouchEvent()
method.Also if you want to keep interact with main content fragment while drawer is open you should add this line at the beginning of the method.
Based on the other answer which I wrote here. I have modified the code to suit your question. Please check.
Check more about touch hierarchy here
dispatchTouchEvent()
method should be overridden inActivity
classNote: As mentioned in the question comments, this is against of Android guidelines. So try to avoid it until unless it is mandatory.