Don't hide the navigation drawer

I am creating an application where I want to show some additional data about the content displayed on the screen using a navigation drawer. By default, after clicking on the drawer is hidden - I would like to override this behavior. I want to keep the drawer open for as long as I click on it and also redirects click events to the main views.

Is it possible? If not with a drawer layout, how can I implement this functionality?

+3


source to share


1 answer


I solved this by extending DrawerLayout and overriding onInterceptTouchEvent:

public class CustomDrawerLayout extends DrawerLayout {
    // .... Constructors here...

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final boolean result = super.onInterceptTouchEvent(ev);
        if (isDrawerOpen(Gravity.RIGHT)) {
            switch (ev.getAction()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_UP: {
                    return false;
                }
            }
        }
        return result;
    }
}

      

In the above example, you will be able to interact with the content below when the right drawer opens. Don't change foreget DrawerLayout to CustomDrawerLayout in your main layout XML file.



Also, you may need to hide the hidden overlay that appears above the rest of the layout to use:

mDrawerLayout.setScrimColor(Color.TRANSPARENT);

      

+1


source







All Articles