Navigation Drawer with webview auto-closes after scrolling


I've put a webview on the Navigation Drawer; the webview shows formatted text about the current UI so that the users can familiarize themselves with features.

Unfortunately, after scrolling up or down on the webview (horizontal scrolling of the webview is disabled), the navigation drawer closes itself after I lift my finger off the webview !

How can I prevent the Navigation Drawer from closing itself when the user lets go ?

EDIT: additional findings ... I've attached an OnTouchListener() to the drawer's layout that does nothing except return true. This prevents the auto-closing from happening when touching an empty space on the Navigation Drawer. To see how this is done, check out <a href="http://android-er.blogspot.com/2014/01/android-drawerlayout-and-drawerlistener.html" rel="nofollow">http://android-er.blogspot.com/2014/01/android-drawerlayout-and-drawerlistener.html</a> and look at the "experimental" comment.

<strong>Unfortunately</strong> it doesn't stop the Navigation Drawer from closing when the user doesn't scroll up/down perfectly on the webview. For example, scrolling up and down on the webview will close the drawer if there is a very small horizontal component to the drag.


So the (hassle-free) solution to prevent the over-zealous closing of the drawer: once the drawer is open, lock it open and have a button trigger the closeDrawer(). The code below shows how to manage the lock/unlock status. It doesn't include the button to call closeDrawer() because that's quite basic.

in XML, the id of the DrawerLayout is :

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" >

in your Activity, the java code is :

import android.support.v4.widget.DrawerLayout; public class MyActivity extends Activity implements DrawerLayout.DrawerListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layoutwithdrawer); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setDrawerListener(this); } @Override public void onDrawerClosed(View arg0) { // allow swiping to open the drawer mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); } @Override public void onDrawerOpened(View arg0) { // disable swiping so that the drawer can't be closed by accident when scrolling through webview mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); } @Override public void onDrawerSlide(View arg0, float arg1) {} @Override public void onDrawerStateChanged(int arg0) {} }


  • (android.support.v4.widget.DrawerLayout$DrawerListener)' on a null object reference
  • com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String t
  • Inherit from two polymorphic classes
  • Windows authentication hybrid
  • How to add informative text to menu strip separator in vb.net or C#
  • How to visualize a sequence of TOF-Sensor data in PCL (with Qt)?
  • Strategy to auto-generate PHP code?
  • replace letters in python string
  • boost interprocess file_lock does not work with multiple processes
  • How can I parse error messages from TypeScript in Sublime Text 2?
  • Modifying resource contents of a running executable
  • How to limit the editable text in JComboBox?
  • installing pip on python 2.7.8 on windows
  • What should be the return value of a custom function addEdge in a new class based on BGL?
  • Jquery ajax error when upgrading to v1.5
  • send data to remote server with jquery ajax
  • ObservableCollection to 1 of 3 listviews depending on some property
  • How to write an install script for ubuntu
  • Why have a private constructor [duplicate]
  • Subviews for custom UIView with Nib (.xib) don't load?
  • Grails 3 - How to publish to Artifactory
  • Connection pooling with URLConnection?
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • Android - Material Design - NavigationView - How to put vertical scroll?
  • Disable Enter in editText android
  • Change multiple background-images with jQuery
  • Cannot resolve symbol 'MyApi'
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Splitting given String into two variables - php
  • Check if a string to interpolate provides expected placeholders
  • Trying to switch camera back to front but getting exception
  • Release, debug version and Authorization Google?
  • Weird JavaScript statement, what does it mean?
  • jquery mobile loadPage not working
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Turn off referential integrity in Derby? is it possible?
  • JaxB to read class hierarchy