android - setDisplayHomeAsUpEnabled 和 setHomeButtonEnabled 有什么区别?

标签 android android-actionbar

我想在操作栏中启用主页按钮。我正在使用此代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            actionbar.setHomeButtonEnabled(true);
            actionbar.setDisplayHomeAsUpEnabled(true);
}

在此我使用 setHomeButtonEnabledsetDisplayHomeAsUpEnabled 在 ActionBar 中的图标处放置一个后退标记。如果我只使用 setDisplayHomeAsUpEnabled 那么它也可以工作吗?是否需要将 setHomeButtonEnabled 设置为 true?

两者有什么区别?

最佳答案

对于你想做的事,actionBar.setDisplayHomeAsUpEnabled(true)够了。

区别:
actionBar.setHomeButtonEnabled(true)只会使图标可点击,图标背景的颜色作为点击的反馈。
actionBar.setDisplayHomeAsUpEnabled(true)将使图标可点击并添加<在图标的左侧。

关于android - setDisplayHomeAsUpEnabled 和 setHomeButtonEnabled 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13492280/

相关文章:

android - FragmentPagerAdapter notifyDataSetChanged 不起作用

android - 为什么函数 "if (counter >10)"不能工作?

android - 如何隐藏 ActionBar 中的 ChromeCast MediaRoute MenuItem?

android.support.v7 Toolbar & DrawerLayout- 如何改变汉堡图标

Android 风格应用 minSdkVersion ="8"targetSdkVersion ="21"

android - 应用程序未出现在特定设备的 Android Market 中(Android Market 过滤器)

java - Android 两点之间缩放

android - 在Android的“回收器” View 中制作You-tube视频播放器

android - ActionBar 上特定菜单项的不同外观/样式

android - Actionbar 颜色在 android 中没有改变(Lollipop)