对于ActionBarDrawerToggle

时间:2015-05-31 05:52:10

标签: android android-actionbar navigation-drawer drawerlayout actionbardrawertoggle

我尝试使用支持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的外观和功能?

1 个答案:

答案 0 :(得分:0)

可以说,如果您有一个左侧抽屉用于导航,可以通过左侧滑动打开,您应该始终在左上角打开汉堡包进行打开。使您的导航层次结构变得混乱,因为它不遵守汉堡包菜单的常用惯例。

其次,不推荐使用v4切换,使用v7。