-1

I want to put one back button in title bar area to go on back activity in Android app how to put that button.

enter image description here

Like there is in this image.

Zong
  • 6,160
  • 5
  • 32
  • 46
newCode
  • 178
  • 1
  • 3
  • 15
  • 1
    What have you tried? Where is some of your code you are having trouble with? Don't come here expecting this community to do your work for you. – SQLiteNoob May 01 '14 at 14:12
  • 1
    i don't even know how to modify title bar that's why i am asking Dude. – newCode May 01 '14 at 14:19

1 Answers1

7

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 :

Android Docs

vjdhama
  • 4,878
  • 5
  • 33
  • 47