Search code examples
javaandroidandroid-activitymenuback-button

Button back in top android menu is missing


I use Android Studio 1.5 to create an Android application.

I added a blank activity using context menu but I forgot to define a hierarchical parent for that activity.

So I changed in AndroidManifest.xml this

  <activity
            android:name=".CategoriesActivity"
            android:label="@string/title_activity_categories"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>

to this

  <activity
            android:name=".CategoriesActivity"
            android:label="@string/title_activity_categories"
            android:parentActivityName=".CitiesActivity"
            android:theme="@style/AppTheme.NoActionBar">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="info.emitikon.mycity.CitiesActivity" />
        </activity>

Anyway I cannot see the BACK arrow button at the top menu.

What do I am missing here?


Solution

  • Add these lines in the onCreate method of your Activity:

    ActionBar = getActionBar(); // or getSupportActionBar() if you are using the suport library
    
    actionBar.setHomeAsUpIndicator(R.drawable.ic_launcher); // your custom icon
    actionBar.setDisplayShowHomeAsUpEnabled(true);