操作栏图标继续显示返回图标
action bar icon keep showing back icon
我在开发 android 应用程序方面确实是个新手。我的项目在片段之间使用导航抽屉。我尝试使用教程 http://www.tutecentral.com/android-custom-navigation-drawer/ 自定义抽屉,但出现错误。在我的应用程序中,在操作栏中,它一直显示返回图标而不是默认图标。
这是 url 操作栏的前后图像: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 更改为其他可绘制图标,但没有效果。
尝试在 manifest
文件中为 activity
设置主题,并在 styles.xml
中为该主题 homeAsUpIndicator
设置可绘制对象
<style name="CustomTheme" parent="@style/Widget.AppCompat.ActionBar">
<item name="homeAsUpIndicator">@drawable/ic_drawer</item>
</style>
我在开发 android 应用程序方面确实是个新手。我的项目在片段之间使用导航抽屉。我尝试使用教程 http://www.tutecentral.com/android-custom-navigation-drawer/ 自定义抽屉,但出现错误。在我的应用程序中,在操作栏中,它一直显示返回图标而不是默认图标。
这是 url 操作栏的前后图像: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 更改为其他可绘制图标,但没有效果。
尝试在 manifest
文件中为 activity
设置主题,并在 styles.xml
中为该主题 homeAsUpIndicator
设置可绘制对象
<style name="CustomTheme" parent="@style/Widget.AppCompat.ActionBar">
<item name="homeAsUpIndicator">@drawable/ic_drawer</item>
</style>