【问题标题】:action bar icon keep showing back icon操作栏图标不断显示返回图标
【发布时间】:2015-05-14 21:07:02
【问题描述】:

我在开发 android 应用程序方面确实是新手。我的项目在片段之间使用导航抽屉。我尝试使用教程http://www.tutecentral.com/android-custom-navigation-drawer/ 自定义抽屉,但出现错误。在我的应用程序中,在操作栏中,它一直显示返回图标而不是默认图标。

这是操作栏前后图像的网址:http://oi58.tinypic.com/2ahsbys.jpg

这是我感到困惑的代码(与教程几乎相同,告诉我是否遗漏了什么)

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_drawer, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };

如果我删除 setDisplayHomeAsUpEnabled,后退图标消失了,但我无法单击某处来显示抽屉,我必须滑动它。如果有人解决了,请参考我。非常感谢。

*我已将 R.drawable.ic_drawer 更改为其他可绘制图标,但没有任何效果。

【问题讨论】:

标签: android android-fragments android-actionbar


【解决方案1】:

尝试在manifest 文件和styles.xml 中为您的activity 设置一个主题,为该主题设置homeAsUpIndicator 的drawable

<style name="CustomTheme" parent="@style/Widget.AppCompat.ActionBar"> 
     <item name="homeAsUpIndicator">@drawable/ic_drawer</item> 
</style>

【讨论】: