我在DrawerLayout中有两个导航片段。左侧有一个导航片段,右侧有一个导航片段。
在某些情况下,我需要打开左侧导航片段并将其锁定。
当我只离开导航片段时,我使用了drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
但是当我在右侧添加第二个导航片段时,此方法开始打开并锁定两个面板。
如果在这种情况下只打开并锁定左侧导航视图?
答案 0 :(得分:1)
像这样改变你的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer_layout);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mLeftDrawerList = (ListView) findViewById(R.id.left_drawer);
mRightDrawerList = (ListView) findViewById(R.id.right_drawer);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,R.drawable.ic_drawer, R.string.drawer_open,R.string.drawer_close) {
public void onDrawerOpened(View view){
if(view.equals(mRightDrawerList)) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mLeftDrawerList);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mRightDrawerList);
}
invalidateOptionsMenu();
}
public void onDrawerClosed(View view) {
if(view.equals(mRightDrawerList)) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mLeftDrawerList);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mRightDrawerList);
}
invalidateOptionsMenu();
}
});
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
这应该有用。