Java – setDisplayHomeAsUpEnabled does not display a back arrow with a custom action bar View

setDisplayHomeAsUpEnabled does not display a back arrow with a custom action bar View… here is a solution to the problem.

setDisplayHomeAsUpEnabled does not display a back arrow with a custom action bar View

When I click on the icon where it works as expected, everything in the list is set correctly, but not on the ActionBar

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.actionbar_view);

Solution

You pass The bit of ActionBar.setDisplayOptions tells ActionBar to display only the Home icon and your custom View. You should also pass in ActionBar.DISPLAY_HOME_ AS_UP. Such as:

actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP
        | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_CUSTOM);

Alternatively, simply call ActionBar.setDisplayShowCustomEnabled :

actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.actionbar_view);

Related Problems and Solutions