set ActionBar Visible - Android User Interface

Android examples for User Interface:ActionBar

Description

set ActionBar Visible

Demo Code


import android.content.res.Resources;
import android.os.Build;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.appcompat.R;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.reflect.Field;

public class Main{
    public static void setActionBarVisible(ActionBarActivity activity,
            boolean isVisible) {
        View decorView = activity.getWindow().getDecorView();
        int resId;
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
                || Build.VERSION.SDK_INT >= 21/*
                                               * Build
                                               * .
                                               * VERSION_CODES
                                               * .
                                               * LOLLIPOP
                                               */) {
            resId = activity.getResources()
                    .getIdentifier("action_bar_container", "id",
                            activity.getPackageName());
        } else {/*from  w w  w. j  a  v  a2  s  .c om*/
            resId = Resources.getSystem().getIdentifier(
                    "action_bar_container", "id", "android");
        }

        if (resId != 0) {
            decorView.findViewById(resId).setVisibility(
                    isVisible ? View.VISIBLE : View.GONE);
        }
    }
}

Related Tutorials