是什么setDisplayHomeAsUpEnabled和setHomeButtonEnabled之

2019-07-04 00:52发布

我希望能够在操作栏的主页按钮。 我使用此代码:

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

在此我使用setHomeButtonEnabledsetDisplayHomeAsUpEnabled把背关口图标动作条。 如果我只用setDisplayHomeAsUpEnabled然后也将它的工作? 是否有必要设置setHomeButtonEnabled为真?

两者有什么区别?

Answer 1:

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

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



Answer 2:

由于Android的说:

- setDisplayShowHomeEnabled(boolean showHome)
  // Set whether to include the application home affordance in the action bar.
  // (and put a back mark at icon in ActionBar for "up" navigation)

 -setHomeButtonEnabled(boolean enabled)
  // Enable or disable the "home" button in the corner of the action bar.
  // (clickable or not)

它应该是很清楚的,我认为



文章来源: What is the difference between setDisplayHomeAsUpEnabled and setHomeButtonEnabled?