Вопрос

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.

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top