I have been trying to add a back button to the action bar.
I want my view to look like this:
I want to add the back button in the left of the action bar.
I added this code
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
but it doesn't work.
How can I fix this?
You'll need to check
menuItem.getItemId()
againstandroid.R.id.home
in theonOptionsItemSelected
methodDuplicate of Android Sherlock ActionBar Up button
Use this to show back button and move to previous activity,
if anyone else need the solution
Add this line in onCreate() method
then Override this method
this one worked for me:
The method onSupportNavigateUp() is called when you use the back button in the SupportActionBar.
There are two ways to approach this.
Option 1: Update the Android Manifest If the settings Activity is always called from the same activity, you can make the relationship in the Android Manifest. Android will automagically show the 'back' button in the ActionBar
Option 2: Change a setting for the ActionBar If you don't know which Activity will call the Settings Activity, you can create it like this. First in your activity that extends ActionBarActivity (Make sure your @imports match the level of compatibility you are looking for).
Then, detect the 'back button' press and tell Android to close the currently open Activity.
That should do it!