45

アクションバーのホームボタンを有効にしたい。私はこのコードを使用しています:

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

これでは、ActionBarのアイコンにバックマークを付けるために使用setHomeButtonEnabledしています。setDisplayHomeAsUpEnabled私がそれだけを使用する場合setDisplayHomeAsUpEnabled、それも機能しますか?setHomeButtonEnabledtrueに設定する必要がありますか?

2つの違いは何ですか?

4

2 に答える 2

88

あなたがやりたいことには、actionBar.setDisplayHomeAsUpEnabled(true)十分です。

違いについて:
actionBar.setHomeButtonEnabled(true)クリックのフィードバックとしてアイコンの背景の色で、アイコンをクリック可能にするだけです。アイコンをクリック可能にし、アイコンの左側にを
actionBar.setDisplayHomeAsUpEnabled(true)追加します。<

于 2012-11-21T11:38:00.133 に答える
7

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)

それはかなり明確であるべきだと思います

于 2012-11-21T11:41:58.440 に答える