ActionBarDrawerToggle 类型未定义方法 setHomeAsUpIndicator

The method setHomeAsUpIndicator is undefined for the type 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);

当我尝试更改指标时,在 ActionBarDrawerToggle 上调用 setDrawerIndicatorEnabled 没有问题,但在尝试调用 setHomeAsUpIndicator 时出现上述错误。我只能在 getSupportActionBar():

上调用 setHomeAsUpIndicator
public void turnOnActionBarUpIndicator()
{
    mDrawerToggle.setDrawerIndicatorEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(null); //this compiles
    mDrawerToggle.setHomeAsUpIndicator(null); //this line does not compile
}

这会导致指示器的外观发生变化,但不会改变它的功能,这意味着我将箭头视为指示器,但它会打开抽屉而不是进入后栈。

如何获得 ActionBar 的外观和功能?

可以说,如果您有一个用于导航的左侧抽屉,可以通过从左侧滑动来打开,您应该始终将汉堡包放在左上角以打开它。使您的导航层次结构有点混乱,因为它不遵守汉堡菜单工作方式的通用约定。

其次,v4 切换已弃用,请使用 v7。