Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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;

publicclassMyActivityextendsActivityimplementsDrawerLayout.DrawerListener
{

    @OverridepublicvoidonCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layoutwithdrawer);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerLayout.setDrawerListener(this);
    }

    @OverridepublicvoidonDrawerClosed(View arg0) {
        // allow swiping to open the drawer
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    }

    @OverridepublicvoidonDrawerOpened(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);
    }

    @OverridepublicvoidonDrawerSlide(View arg0, float arg1) {}

    @OverridepublicvoidonDrawerStateChanged(int arg0) {}
}

Post a Comment for "Navigation Drawer With Webview Auto-closes After Scrolling"