防止 NavigationDrawer 在主页按钮单击时打开 [英] Prevent NavigationDrawer from opening on Home Button Click
问题描述
我的主要活动有一个 NavigationDrawer,在一个实例中,我展示了一个片段,而汉堡菜单"变成了一个箭头.
I have a NavigationDrawer for my main activity, in one instance I show a fragment and the "Hamburger menu" changes into an arrow.
当使用此片段显示时,我禁用了通过滑动打开抽屉的功能
I disabled the ability to open the drawer via swipe when that fragment is shown by using this
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
它工作正常,但现在问题是用户仍然可以通过单击主页按钮箭头"来打开抽屉.我希望箭头充当后退按钮而不是打开抽屉,那么如何阻止抽屉打开?
and it works fine but now the problem is the user can still open the drawer by clicking the home button "Arrow". I want the arrow to act as the back button and not open the drawer so how can I stop the drawer from opening?
推荐答案
我猜你需要使用 setNavigationOnClickListener() 在工具栏上覆盖抽屉行为.
I guess you need to use setNavigationOnClickListener() on toolbar to override drawer behavior.
喜欢 -
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// logic to decide if drawer open/close, or pop fragment etc
}
});
这确实可以防止通过单击图标打开抽屉.但它确实通过滑动打开.但你已经照顾好了.所以这应该有效.
This does prevents drawer from opening by clicking on icon. But it does open by swiping. But that you already taken care of. So this should work.
注意这仅在您通过调用
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer){ ...
这篇关于防止 NavigationDrawer 在主页按钮单击时打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!