unlock drawer_layout when it is locked
Asked Answered
V

2

3

I have a mainactivity where I have created a method to lock/unlock the drawer_layout and locked it in the onCreate() method.

public void disableDrawer(Boolean bol){
    if(bol) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    }else{
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    }
}

and after checking if the user is logged in or not i want to unlock the drawer from the fragment. I tried to do this in onActivityCreated but the drawer is still locked

MainActivity activity = ((MainActivity)getActivity());
activity.disableDrawer(false);

in short

DrawerLayout.LOCK_MODE_UNLOCKED

doesn't unlock DrawerLayout...

any help would be appreciated.

Vindicable answered 22/4, 2014 at 10:41 Comment(1)
You should only use DrawerLayout.LOCK_MODE_LOCKED_CLOSED or DrawerLayout.LOCK_MODE_LOCKED_OPEN, depending if you want your drawer to stay closed or opened.Scab
W
0

you have to initialize toggle again.

toggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); mDrawerLayout.addDrawerListener(toggle);

After that, it unlocked.

Willpower answered 19/1, 2018 at 6:24 Comment(0)
T
0

After struggling a little.. nothing among other solutions in stackoverflow worked for me. My specific problem was also that I was able to lock but not to unlock the DrawerLayout.

Then I saw in documentation (https://developer.android.com/reference/android/support/v4/widget/DrawerLayout#setdrawerlockmode) that there are two more functions:

void setDrawerLockMode (int lockMode, View drawerView)
void setDrawerLockMode (int resId, int edgeGravity)

The second one worked for me like a charm.

I simply specified the Gravity.LEFT parameter and now all is working perfectly.

Theall answered 12/5, 2018 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.