问题描述
我有一个活动具有
类。这种布局显示在抽屉列表,并让用户能够 DrawerLayout
片段
之间切换。在这些片段
,也有一些网址,当用户clicsk,一个 WebviewFragment
将被显示。不过,我不希望在 WebViewFragment
显示 DrawerLayout
。相反,我会preFER用户会被重定向到previous 片段
。
I have an Activity
class that have a DrawerLayout
. That layout shows a list in Drawer and let user to switch between fragments
. In these Fragments
, there are some URLs and when user clicsk on that, a WebviewFragment
would be shown. However, I don't want to show the DrawerLayout
in the WebViewFragment
. Instead, I would prefer user would being redirected to previous Fragment
.
有没有办法对我来说,显示/隐藏 DrawerLayout
取决于当前有哪些片段
是?
我尝试调用 mDrawerLayout.setVisibility(View.GONE
),但它似乎是不完整的。至少动作条
图标仍然抽屉图标。
Is there any way for me to show/hide the DrawerLayout
depends on what the current Fragment
is?I try to call mDrawerLayout.setVisibility(View.GONE
), but it seems that it is not complete. At least the ActionBar
icon is still the drawer icon.
推荐答案
您可以使用此方法来锁定或解锁抽屉:<$c$c>DrawerLayout.setDrawerLockMode(...)$c$c>. (也有这种方法来为特定的抽屉的锁模式的另外两个版本。)要锁定,使用 DrawerLayout.LOCK_MODE_LOCKED_CLOSED
;解锁,使用 DrawerLayout.LOCK_MODE_UNLOCKED
。
You can use this method to lock or unlock the drawer: DrawerLayout.setDrawerLockMode(...)
. (There are also two other versions of this method to specify a lock mode for specific drawers.) To lock, use DrawerLayout.LOCK_MODE_LOCKED_CLOSED
; to unlock, use DrawerLayout.LOCK_MODE_UNLOCKED
.
如果您使用的是ActionBarDrawerToggle,你需要一些额外的code从打开添加到prevent抽屉里,当他们点击ActionBarDrawerToggle如果你已经锁定了抽屉里。
If you are using the ActionBarDrawerToggle, you need to add some extra code to prevent the drawer from opening when they click the ActionBarDrawerToggle if you've locked the drawer.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// check lock mode before passing to ActionBarDrawerToggle
// I assume your drawer is on the left; if not, use Gravity.RIGHT
int lockMode = mDrawer.getDrawerLockMode(Gravity.LEFT);
if (lockMode == DrawerLayout.LOCK_MODE_UNLOCKED &&
mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
return super.onOptionsItemSelected(item);
}
这篇关于显示/隐藏DrawerLayout取决于当前片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!