Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
819 views
in Technique[技术] by (71.8m points)

android - unlock drawer_layout when it is locked

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...