Request the ActionBar window feature if we are on a supported Android version. - Android User Interface

Android examples for User Interface:ActionBar

Description

Request the ActionBar window feature if we are on a supported Android version.

Demo Code

/* ActivityHelper.java//from   w  ww . ja va  2  s. c  o m
 * See the file "LICENSE.md" for the full license governing this code.
 */
//package com.java2s;
import android.annotation.TargetApi;

import android.app.Activity;

import android.os.Build;

import android.view.Window;

public class Main {
    /**
     * Request the ActionBar window feature if we are on a supported Android
     * version. This should be called before the activity's setContentView.
     *
     * @param activity
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void addActionBarIfSupported(Activity activity) {
        if (actionBarSupported()) {
            activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
        }
    }

    private static boolean actionBarSupported() {
        return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB;
    }
}

Related Tutorials