我想在菜单中,单击要打开的右抽屉我用下面的代码,但它不工作由于某种原因
mDrawerToggle = new ActionBarDrawerToggle(getActivity(),mDrawerLayout,toolbar, R.string.drawer_open,
R.string.drawer_close) {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item != null && item.getItemId() == R.id.more) {
if (mDrawerLayout.isDrawerOpen(Gravity.END)) {
saveToPreferences(getActivity(),KEY_USER_LEARNED_DRAWER,mUserLearnedDrawer+"");
mDrawerLayout.closeDrawer(Gravity.END);
} else {
mDrawerLayout.openDrawer(Gravity.END);
}
}
return false;
}
};
请帮我
解决它通过修改在MainActivity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
return true;
case R.id.more:
if (notificationDrawerFragment.mDrawerLayout.isDrawerOpen(Gravity.END)){
notificationDrawerFragment.mDrawerLayout.closeDrawer(Gravity.END);
}
else
{ notificationDrawerFragment.mDrawerLayout.openDrawer(Gravity.END);
}
default:
return super.onOptionsItemSelected(item);
}
}