我尝试使用支持v4 ActionBarDrawerToggle
,以便将操作栏指示器更改为后箭头而不是导航抽屉的3个点。我还使用了v4 Fragment
,v4 Drawerlayout
,v7 ActionBar
和v7 ActionBarActivity
。
这就是我使用它的方式:
在onCreate中:
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
当我尝试更改指标时,我在setDrawerIndicatorEnabled
上调用ActionBarDrawerToggle
时没有遇到任何问题,但在尝试调用setHomeAsUpIndicator
时出现上述错误。我只能在setHomeAsUpIndicator
上致电getSupportActionBar()
:
public void turnOnActionBarUpIndicator()
{
mDrawerToggle.setDrawerIndicatorEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(null); //this compiles
mDrawerToggle.setHomeAsUpIndicator(null); //this line does not compile
}
这导致指示器的外观发生变化,但不是它的功能意味着我看到一个箭头作为指示器,但它打开了抽屉,而不是向后上升。
如何同时获得ActionBar
的外观和功能?
答案 0 :(得分:0)
可以说,如果您有一个左侧抽屉用于导航,可以通过左侧滑动打开,您应该始终在左上角打开汉堡包进行打开。使您的导航层次结构变得混乱,因为它不遵守汉堡包菜单的常用惯例。
其次,不推荐使用v4切换,使用v7。