我在我的主活动中设置了一个导航抽屉。在我的一个片段中,我想隐藏汉堡图标并显示返回箭头(已实现)。
ActionBar bar = mMainActivity.getSupportActionBar();
bar.setDisplayShowHomeEnabled(true);
bar.setDisplayHomeAsUpEnabled(true);
bar.setDefaultDisplayHomeAsUpEnabled(true);
问题是,如果我点击箭头,它会打开抽屉。所以我添加了这个:
mMainActivity.mActionBarDrawerToggle.setDrawerIndicatorEnabled(false);
问题是,当我添加了这一行,什么都没有显示。抽屉图标和返回或向上的图标都没有。所以有人可以告诉我我做错了什么吗?编辑
似乎有些混淆关于我已经做过什么和没有做过什么。
mMainActivity.mActionBarDrawerToggle.setDrawerIndicatorEnabled(false);
是暂时添加的,我再次将其删除,因为当我这样做时,没有图标显示,无论是导航抽屉还是返回箭头。下面是我如何处理菜单项点击的方式:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()){
case R.id.search_badge:
L.i("search", "search");
return false;
case android.R.id.home:
L.i("home", "home pressed");
break;
case R.id.action_done:
actionDone();
//for testing
//checkSelectedInterests();
//TODO: MLC
L.i("done", "done pressed");
break;
default:
;;
}
return super.onOptionsItemSelected(item);
}
然而
case android.R.id.home:
L.i("home", "home pressed");
break;
从未被触发
希望这能澄清问题。目前,导航抽屉图标被隐藏,返回箭头被显示。当我点击返回箭头时,它打开了导航抽屉而不是进入我的switch case。