如何在活动的特定片段中禁用抽屉选项 [英] How to disable drawer option in specific fragments of an activity

查看:87
本文介绍了如何在活动的特定片段中禁用抽屉选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5个片段的活动,我在活动中为抽屉使用了抽屉布局,但是我想仅在片段2中使用(启用)抽屉,并且我想在其余片段中禁用抽屉选项.

I have an activity with 5 fragments, I used drawer layout in my activity for a drawer, but I want to use(enable) the drawer in only fragment 2 and I want to disable the drawer option in remaining fragments.

有人可以帮我怎么做吗?

Can any one help me how to do this?

推荐答案

在您的activity中放入两种方法,一种禁用drawer,另一种再次启用它,如下所示:

Put two methods in the your activity, one to disable the drawer and one to enable it again, like so:

public void lockDrawer() {
    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}


public void unlockDrawer() {
    drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}

然后在您的fragments onCreateView(...)方法中放入:

Then in your fragments onCreateView(...) method put:

fragmentInteractionListener.lockDrawer();

对于fragments,其中drawer应保持关闭状态,对于fragments,其中drawer应保持打开状态,

for the fragments where the drawer should stay shut and for the fragments where the drawer should stay open put:

fragmentInteractionListener.unlockDrawer();

PS:有关如何正确实现fragment交互侦听器的教程,请参见:

P.S: for tutorials in how to correctly implement a fragment interaction listener see:

https://developer.android.com/training/basics/fragments/communication.html

这篇关于如何在活动的特定片段中禁用抽屉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆