我有一个带有"后退按钮的工具栏"在左侧和一个按钮打开右侧的导航抽屉片段。现在,如果我点击右侧的按钮,然后点击左侧的后退按钮,应用程序崩溃并说:"没有抽屉视图,重力为LEFT"。是的,片段在右侧,问题是如何避免这种情况?这是我的代码:
在OnCreate中:
setSupportActionBar(toolbarTutorial);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (id == R.id.editInformations) {
drawerLayout.setDrawerListener(new ActionBarDrawerToggle(ProfileActivity.this,
drawerLayout, toolbarTutorial, R.string.drawer_open,R.string.drawer_close){
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
mSlideState = false;
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
mSlideState = true;
}
});
clickEventSlide();
}
和clickEventSlide方法:
public void clickEventSlide(){
if(mSlideState){
drawerLayout.closeDrawer(Gravity.END);
}else{
drawerLayout.openDrawer(Gravity.END);
}}