Sets up ActionBar back arrow and title. - Android User Interface

Android examples for User Interface:ActionBar Title

Description

Sets up ActionBar back arrow and title.

Demo Code


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

public class Main{
    /**/*from www. j  av a  2  s .  c  om*/
     * 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);
    }
}

Related Tutorials