无法更改NavigationDrawer的抽屉图标

use*_*644 20 navigation android drawer navigation-drawer

我正在尝试实现NavigationDrawer自上一次Android主题演讲以来提供的新功能.

我把所有东西都搞定了,当按下左上角的图标时,导航抽屉会打开和关闭.

但是现在我仍然有箭头图标,虽然我用Android中的ic_drawer替换了它.为什么?

这是我指定图标的代码:

mDrawerToggle = new ActionBarDrawerToggle(
            this,                 
            mDrawerLayout,         
            R.drawable.ic_drawer, //<-- This is the icon provided by Google itself
            R.string.drawer_open,
            R.string.drawer_close 
            )
Run Code Online (Sandbox Code Playgroud)

但该应用程序仍然使用标准图标运行setDisplayHomeAsUpEnabled.

有任何想法吗?

use*_*644 48

我只是让导航抽屉工作.我忘了添加developer.android.com示例提供的以下方法:

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    mDrawerToggle.onConfigurationChanged(newConfig);
}
Run Code Online (Sandbox Code Playgroud)

  • 我有同样的问题,但只是使用较旧的设备,如2.3.我的代码已经像你的一样,问题一直困扰着我.. (2认同)