Android StatusBar 状态栏颜色设置

方案一

两种方式:

1.代码方式

/**

    * 设置透明状态栏

*

    * 可在Activity的onCreat()中调用

*

    * 注意:需在顶部控件布局中加入以下属性让内容出现在状态栏之下:

    * android:clipToPadding="true"  // true 会贴近上层布局 ; false 与上层布局有一定间隙

    * android:fitsSystemWindows="true"  //true 会保留actionBar,title,虚拟键的空间 ; false 不保留

    *

*@paramactivity activity

    */

    public static void setTransparentStatusBar(Activity activity) {

//5.0及以上

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            View decorView = activity.getWindow().getDecorView();

            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;

            decorView.setSystemUiVisibility(option);

            activity.getWindow().setStatusBarColor(Color.TRANSPARENT);

//4.4到5.0

}elseif(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

            WindowManager.LayoutParams localLayoutParams = activity.getWindow().getAttributes();

            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);

        }

    }

    ---------------------分割线--------------------------

2.在values,values-v19,values-v21目录下分别 创建主题

//values

//values-v19

//values-v21


Android StatusBar 状态栏颜色设置_第1张图片

你可能感兴趣的:(Android StatusBar 状态栏颜色设置)