Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between setDisplayHomeAsUpEnabled and setHomeButtonEnabled?

I want to enable the home button in the Action bar. I'm using this code:

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

In this I'm using setHomeButtonEnabled and setDisplayHomeAsUpEnabled to put a back mark at icon in ActionBar. If I use only setDisplayHomeAsUpEnabled then also will it work? Is there a need to set setHomeButtonEnabled to true?

What is the difference between the two?

like image 389
Jainendra Avatar asked Nov 21 '12 11:11

Jainendra


People also ask

What is setDisplayShowHomeEnabled?

setDisplayShowHomeEnabled() specifies whether or not the Home button is shown. ActionBar. setDisplayHomeAsUpEnabled() specifies whether or not the Home button has the arrow used for Up Navigation next to it.

How do I use Getupportactionbar?

To use the ActionBar utility methods, call the activity's getSupportActionBar() method. This method returns a reference to an appcompat ActionBar object. Once you have that reference, you can call any of the ActionBar methods to adjust the app bar. For example, to hide the app bar, call ActionBar.


2 Answers

For what you want to do, actionBar.setDisplayHomeAsUpEnabled(true) is enough.

For the difference :
actionBar.setHomeButtonEnabled(true) will just make the icon clickable, with the color at the background of the icon as a feedback of the click.
actionBar.setDisplayHomeAsUpEnabled(true) will make the icon clickable and add the < at the left of the icon.

like image 155
yDelouis Avatar answered Oct 19 '22 14:10

yDelouis


As Android says:

- 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)

It should be quite clear i think

like image 9
kinghomer Avatar answered Oct 19 '22 12:10

kinghomer