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
.
It could be too late to answer but I have a shorter and more functional solution in my opinion.
This is simple and works for me very well
add this inside onCreate() method
add this outside oncreate() method
Try this, In your onCreate()
And for clickevent,
Add below code in the onCreate function:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
And then override: @Override public boolean onOptionsItemSelected(MenuItem item){ onBackPressed(); return true; }