I want to put one back button in title bar area to go on back activity in Android app how to put that button.
Like there is in this image.
I want to put one back button in title bar area to go on back activity in Android app how to put that button.
Like there is in this image.
Assign a parent Activity in Manifest.xml
like this :
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- The meta-data element is needed for versions lower than 4.1 -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
Then in Activity's onCreate()
:
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
And at last in onOptionsItemSelected
:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
Here is more if you need :