setup Back Button for ActionBarActivity - Android android.app

Android examples for android.app:Activity

Description

setup Back Button for ActionBarActivity

Demo Code

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import java.util.HashMap;

public class Main{

    /**//from   w  ww.  j ava 2  s. c  o  m
     * Sets up <code>ActionBar</code> back arrow and title.
     */
    public static void setupBackButton(ActionBarActivity activity,
            int titleResId) {
        setupBackButton(activity, activity.getString(titleResId));
    }
    public static void setupBackButton(ActionBarActivity activity,
            String title) {
        activity.getSupportActionBar().setTitle(title);
        activity.getSupportActionBar().setHomeButtonEnabled(true);
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    public static void setupBackButton(Activity activity, int titleResId) {
        setupBackButton(activity, activity.getString(titleResId));
    }
    public static void setupBackButton(Activity activity, String title) {
        activity.getActionBar().setTitle(title);
        activity.getActionBar().setHomeButtonEnabled(true);
        activity.getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    public static void setupBackButton(ActionBarActivity activity,
            String title) {
        activity.getSupportActionBar().setTitle(title);
        activity.getSupportActionBar().setHomeButtonEnabled(true);
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    /**
     * Sets up <code>ActionBar</code> back arrow and title.
     */
    public static void setupBackButton(ActionBarActivity activity,
            int titleResId) {
        setupBackButton(activity, activity.getString(titleResId));
    }

}

Related Tutorials