Set the home button in ActionBar for returning to parent Activity - Android User Interface

Android examples for User Interface:ActionBar

Description

Set the home button in ActionBar for returning to parent Activity

Demo Code


import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class Main{
    /**//from  ww  w  . j  a  v a  2 s .c o m
     * Set the home button in ActionBar for returning to parent Activity
     *
     * @param activity
     */
    public static void setSupportActionBarHomeButton(
            AppCompatActivity activity) {
        ActionBar actionBar = activity.getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }
}

Related Tutorials