package com.lzy.headerviewpager; import android.content.Context; import android.graphics.Color; import java.util.Random; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy0216 * 版 本:1.0 * 创建日期:2016/5/8 * 描 述: * 修订历史: * ================================================ */ public class Utils { /** 生成漂亮的颜色 */ public static int generateBeautifulColor() { Random random = new Random(); //为了让生成的颜色不至于太黑或者太白,所以对3个颜色的值进行限定 int red = random.nextInt(150) + 50;//50-200 int green = random.nextInt(150) + 50;//50-200 int blue = random.nextInt(150) + 50;//50-200 return Color.rgb(red, green, blue);//使用r,g,b混合生成一种新的颜色 } /** 获得状态栏的高度 */ public static int getStatusHeight(Context context) { int statusHeight = -1; try { Class<?> clazz = Class.forName("com.android.internal.R$dimen"); Object object = clazz.newInstance(); int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString()); statusHeight = context.getResources().getDimensionPixelSize(height); } catch (Exception e) { e.printStackTrace(); } return statusHeight; } }