本文介绍了锁定抽屉时解锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mainactivity,其中我创建了一种方法来锁定/解锁抽屉式布局并将其锁定在onCreate()方法中.

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);
    }
}

,并在检查用户是否登录后,我想从片段中解锁抽屉.我尝试在onActivityCreated中执行此操作,但抽屉仍处于锁定状态

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);

简而言之

DrawerLayout.LOCK_MODE_UNLOCKED

没有解锁DrawerLayout ...

任何帮助将不胜感激.

推荐答案

经过一番努力后.stackoverflow中的其他解决方案对我没有任何帮助.我的特定问题还在于我能够锁定但无法解锁DrawerLayout.

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.

然后我在文档中看到了( https://developer .android.com/reference/android/support/v4/widget/DrawerLayout#setdrawerlockmode ),还有另外两个功能:

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.

我只是指定了Gravity.LEFT参数,现在一切正常.

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

这篇关于锁定抽屉时解锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 15:28