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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With