Sets the support action bar back button - Android android.app

Android examples for android.app:Action Bar

Description

Sets the support action bar back button

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.view.View;
import android.view.Window;

public class Main{

    /**//  w w  w  . ja  v  a 2 s.c  o m
     * Sets the support action bar back button. The activity still has to manage the back button
     * event correctly!
     *
     * @param delegate AppCompatDelegate for the AppCompatActivity you want to modify.
     */
    public static void setSupportActionBarBack(
            @NonNull AppCompatDelegate delegate) {
        ActionBar bar = delegate.getSupportActionBar();
        if (bar != null) {
            delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
            delegate.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

}

Related Tutorials