在一个活动中我有两个片段。 当片段A显示时,我希望导航抽屉汉堡图标显示并且导航抽屉正常工作。 当片段B显示时,我希望返回箭头显示,并且在点击后进行上导航。 但是,除非导航抽屉打开,否则我似乎无法使新的AppCompat v7工具栏在我的ActionBarActivity内显示向上箭头。
在我的活动中,对于我的onCreate()方法,我有...
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
}
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
mDrawerLayout.setDrawerListener(mDrawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
然后我在我的onPostCreate()函数中调用mDrawerToggle.syncState();
我尝试搜索如何以编程方式触发工具栏图标的后退箭头,但没有任何效果。据我所了解,调用
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
我希望从我的片段中更改图标,但实际情况并非如此。这可能是一个愚蠢的问题,但我做错了什么?