Display back button on action bar

Dany Maor picture Dany Maor · Mar 28, 2013 · Viewed 316.5k times · Source

I'm trying to display a Back button on the Action bar to move previous page/activity or to the main page (first opening). And I can not do it.

my code.

ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);

the code is in onCreate.

Answer

fhamicode picture fhamicode · Jul 23, 2013

well this is simple one to show back button

actionBar.setDisplayHomeAsUpEnabled(true);

and then you can custom the back event at onOptionsItemSelected

case android.R.id.home:
this.finish();
return true;