码迷,mamicode.com
首页 > 其他好文 > 详细

StatusBarUtils工具类

时间:2017-06-16 19:32:21      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:lag   void   android   导航   ams   stat   状态   oid   order   

 

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"); //改变状态栏的颜色

 

StatusBarUtils工具类

标签:lag   void   android   导航   ams   stat   状态   oid   order   

原文地址:http://www.cnblogs.com/galibujianbusana/p/7028769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!