Disable wipes for an open drawer, but NOT to close

I want to disable the opening of the drawer using a swipe, but not the closing using the scroll or return button.

I use fragments in my drawer, so when the drawer opens, I replace my fragment and add it to the stack. When you click on the stand, the drawer closes as an aspect.

But when I use

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

as in this post: disable gestures, which opens the navigation box in android it disables ALL swipes and navigation navigation. The only way to close the drawer now is to touch the screen outside the drawer.

Is there an alternative to LockMode and keep the navigation closed and back?

Note. I am using Android 5.0.1

+4
source share
1 answer

I found a workaround to achieve what I want:

I initially set drawerMode to CLOSED. After opening it, for example, through a button, I will unlock the box to confirm the gesture again. After closing the drawer, the lock for opening will be activated. For this I use the ActionBarDrawerToggle interface

    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 get around drawerlayout or parts of it, but it would be nice to get what I want.

I hope this solution will be useful to others.

+6
source

Source: https://habr.com/ru/post/1626517/


All Articles