zoukankan      html  css  js  c++  java
  • StatusBarUtils工具类

    import android.app.Activity;
    import android.app.Dialog;
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.graphics.Color;
    import android.os.Build;
    import android.view.View;
    import android.view.Window;
    import android.view.WindowManager;
    
    public class StatusBarUtils {
        public static void setWindowStatusBarColor(Activity activity, String color) {
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Window window = activity.getWindow();
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.setStatusBarColor(Color.parseColor(color));
    
                    //底部导航栏
                    //window.setNavigationBarColor(activity.getResources().getColor(colorResId));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void setWindowStatusBarColor(Dialog dialog, String color) {
            try {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    Window window = dialog.getWindow();
                    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                    window.setStatusBarColor(Color.parseColor(color));
    
                    //底部导航栏
                    //window.setNavigationBarColor(activity.getResources().getColor(colorResId));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void RippleView(View view, Context context)
        {
            if(android.os.Build.VERSION.SDK_INT >= 21)
            {
                int[] attrsArray = { android.R.attr.selectableItemBackgroundBorderless };
                //TypedArray typedArray = activity.obtainStyledAttributes(attrsArray);
                TypedArray typedArray = context.obtainStyledAttributes(attrsArray);
                int selector = typedArray.getResourceId(0, attrsArray[0]);
                view.setBackgroundResource(selector);
                // don't forget the resource recycling
                typedArray.recycle();
            }
            else
            {
                int[] attrsArray = { android.R.attr.selectableItemBackground };
                TypedArray typedArray = context.obtainStyledAttributes(attrsArray);
                //TypedArray typedArray = getActivity().obtainStyledAttributes(attrsArray);
                int selector = typedArray.getResourceId(0, attrsArray[0]);
                view.setBackgroundResource(selector);
                typedArray.recycle();
            }
    
        }
    }
    StatusBarUtils.setWindowStatusBarColor(this,"#D43B33"); //改变状态栏的颜色
    今天多一点积累,明天少一分烦恼
  • 相关阅读:
    Poj3295 tautology
    Poj2586 每五个月都是亏
    Poj 2109 k^n = p.
    Poj2109 (2) k^n = p.
    Poj2109 (1) k^n = p.
    Poj2965 冰箱的开关
    Poj1328 用雷达覆盖所有的岛屿
    FASTER-RCNN
    卷积、池化计算
    理论感受野的计算
  • 原文地址:https://www.cnblogs.com/galibujianbusana/p/7028769.html
Copyright © 2011-2022 走看看