程序包 dev.utils.common
类 ColorUtils
java.lang.Object
dev.utils.common.ColorUtils
detail: 颜色工具类 ( 包括常用的色值 )
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
方法概要
修饰符和类型方法说明static intalpha(int color) 返回一个颜色中的透明度值 ( 返回十进制 )static floatalphaPercent(int color) 返回一个颜色中的透明度百分比值static intargb(float alpha, float red, float green, float blue) 根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )static intargb(int alpha, int red, int green, int blue) 根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )static intblendColor(int color1, int color2, float ratio) 使用给定的比例在两种 ARGB 颜色之间进行混合static intblendColor(String color1, String color2, float ratio) 使用给定的比例在两种 ARGB 颜色之间进行混合static intblue(int color) 返回一个颜色中蓝色的色值 ( 返回十进制 )static floatbluePercent(int color) 返回一个颜色中蓝色的百分比值static int[]getARGB(int color) 返回一个颜色 ARGB 色值数组 ( 返回十进制 )static int获取随机颜色值static intgetRandomColor(boolean supportAlpha) 获取随机颜色值static String获取随机颜色值字符串static StringgetRandomColorString(boolean supportAlpha) 获取随机颜色值字符串static intgrayLevel(int color) 获取灰度值static int获取灰度值static intgreen(int color) 返回一个颜色中绿色的色值 ( 返回十进制 )static floatgreenPercent(int color) 返回一个颜色中绿色的百分比值static StringhexAlpha(int alpha) 获取十六进制透明度字符串static StringintToArgbString(int colorInt) 颜色值 转换 ARGB 颜色字符串static StringintToRgbString(int colorInt) 颜色值 转换 RGB 颜色字符串static booleanisARGB(int color) 判断颜色 ARGB 是否有效static booleanisRGB(int color) 判断颜色 RGB 是否有效static booleanjudgeColorString(String colorStr) 判断是否为 ARGB 格式的十六进制颜色, 例如: FF990587static intparseColor(String colorStr) 解析颜色字符串, 返回对应的颜色值static intred(int color) 返回一个颜色中红色的色值 ( 返回十进制 )static floatredPercent(int color) 返回一个颜色中红色的百分比值static intrgb(float red, float green, float blue) 根据对应的 red、green、blue 生成一个颜色值static intrgb(int red, int green, int blue) 根据对应的 red、green、blue 生成一个颜色值static intsetAlpha(int color, float alpha) 设置透明度static intsetAlpha(int color, int alpha) 设置透明度static intsetAlphaDark(int color, int darkValue) 设置透明度加深static intsetAlphaDark(String colorStr, int darkValue) 设置透明度加深static intsetAlphaLight(int color, int lightValue) 设置透明度变浅static intsetAlphaLight(String colorStr, int lightValue) 设置透明度变浅static intsetBlue(int color, float blue) 改变颜色值中的蓝色色值static intsetBlue(int color, int blue) 改变颜色值中的蓝色色值static intsetDark(int color, int darkValue) 颜色加深 ( 单独修改 RGB 值, 不变动透明度 )static int颜色加深 ( 单独修改 RGB 值, 不变动透明度 )static intsetGreen(int color, float green) 改变颜色值中的绿色色值static intsetGreen(int color, int green) 改变颜色值中的绿色色值static intsetLight(int color, int lightValue) 颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )static int颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )static voidsetParser(ColorUtils.ColorInfo.Parser parser) 设置 Color 解析器static intsetRed(int color, float red) 改变颜色值中的红色色值static intsetRed(int color, int red) 改变颜色值中的红色色值static voidsortBrightness(List<ColorUtils.ColorInfo> lists) HSB ( HSV ) Brightness 亮度排序static voidsortGray(List<ColorUtils.ColorInfo> lists) 灰度值排序static voidsortHUE(List<ColorUtils.ColorInfo> lists) HSB ( HSV ) HUE 色相排序static voidsortSaturation(List<ColorUtils.ColorInfo> lists) HSB ( HSV ) Saturation 饱和度排序static inttransitionColor(int startColor, int endColor, float ratio) 计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值static inttransitionColor(String startColor, String endColor, float ratio) 计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值
-
字段详细资料
-
TRANSPARENT
public static final int TRANSPARENT- 另请参阅:
-
WHITE
public static final int WHITE- 另请参阅:
-
WHITE_TRANSLUCENT
public static final int WHITE_TRANSLUCENT- 另请参阅:
-
BLACK
public static final int BLACK- 另请参阅:
-
BLACK_TRANSLUCENT
public static final int BLACK_TRANSLUCENT- 另请参阅:
-
RED
public static final int RED- 另请参阅:
-
RED_TRANSLUCENT
public static final int RED_TRANSLUCENT- 另请参阅:
-
GREEN
public static final int GREEN- 另请参阅:
-
GREEN_TRANSLUCENT
public static final int GREEN_TRANSLUCENT- 另请参阅:
-
BLUE
public static final int BLUE- 另请参阅:
-
BLUE_TRANSLUCENT
public static final int BLUE_TRANSLUCENT- 另请参阅:
-
GRAY
public static final int GRAY- 另请参阅:
-
GRAY_TRANSLUCENT
public static final int GRAY_TRANSLUCENT- 另请参阅:
-
SKYBLUE
public static final int SKYBLUE- 另请参阅:
-
ORANGE
public static final int ORANGE- 另请参阅:
-
GOLD
public static final int GOLD- 另请参阅:
-
PINK
public static final int PINK- 另请参阅:
-
FUCHSIA
public static final int FUCHSIA- 另请参阅:
-
GRAYWHITE
public static final int GRAYWHITE- 另请参阅:
-
PURPLE
public static final int PURPLE- 另请参阅:
-
CYAN
public static final int CYAN- 另请参阅:
-
YELLOW
public static final int YELLOW- 另请参阅:
-
CHOCOLATE
public static final int CHOCOLATE- 另请参阅:
-
TOMATO
public static final int TOMATO- 另请参阅:
-
ORANGERED
public static final int ORANGERED- 另请参阅:
-
SILVER
public static final int SILVER- 另请参阅:
-
DKGRAY
public static final int DKGRAY- 另请参阅:
-
LTGRAY
public static final int LTGRAY- 另请参阅:
-
MAGENTA
public static final int MAGENTA- 另请参阅:
-
HIGHLIGHT
public static final int HIGHLIGHT- 另请参阅:
-
LOWLIGHT
public static final int LOWLIGHT- 另请参阅:
-
-
方法详细资料
-
hexAlpha
获取十六进制透明度字符串- 参数:
alpha- 0-255- 返回:
- 透明度 ( 十六进制 ) 值
-
getARGB
public static int[] getARGB(int color) 返回一个颜色 ARGB 色值数组 ( 返回十进制 )- 参数:
color- argb/rgb color- 返回:
- ARGB 色值数组 { alpha, red, green, blue }
-
alpha
public static int alpha(int color) 返回一个颜色中的透明度值 ( 返回十进制 )- 参数:
color- argb color- 返回:
- alpha 值
-
alphaPercent
public static float alphaPercent(int color) 返回一个颜色中的透明度百分比值- 参数:
color- argb color- 返回:
- alpha 百分比值
-
red
public static int red(int color) 返回一个颜色中红色的色值 ( 返回十进制 )- 参数:
color- argb/rgb color- 返回:
- red 值
-
redPercent
public static float redPercent(int color) 返回一个颜色中红色的百分比值- 参数:
color- argb/rgb color- 返回:
- red 百分比值
-
green
public static int green(int color) 返回一个颜色中绿色的色值 ( 返回十进制 )- 参数:
color- argb/rgb color- 返回:
- green 值
-
greenPercent
public static float greenPercent(int color) 返回一个颜色中绿色的百分比值- 参数:
color- argb/rgb color- 返回:
- green 百分比值
-
blue
public static int blue(int color) 返回一个颜色中蓝色的色值 ( 返回十进制 )- 参数:
color- argb/rgb color- 返回:
- blue 值
-
bluePercent
public static float bluePercent(int color) 返回一个颜色中蓝色的百分比值- 参数:
color- argb/rgb color- 返回:
- blue 百分比值
-
rgb
public static int rgb(int red, int green, int blue) 根据对应的 red、green、blue 生成一个颜色值- 参数:
red- 红色值 [0-255]green- 绿色值 [0-255]blue- 蓝色值 [0-255]- 返回:
- rgb 颜色值
-
rgb
public static int rgb(float red, float green, float blue) 根据对应的 red、green、blue 生成一个颜色值- 参数:
red- 红色值 [0-255]green- 绿色值 [0-255]blue- 蓝色值 [0-255]- 返回:
- rgb 颜色值
-
argb
public static int argb(int alpha, int red, int green, int blue) 根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )- 参数:
alpha- 透明度 [0-255]red- 红色值 [0-255]green- 绿色值 [0-255]blue- 蓝色值 [0-255]- 返回:
- argb 颜色值
-
argb
public static int argb(float alpha, float red, float green, float blue) 根据对应的 alpha、red、green、blue 生成一个颜色值 ( 含透明度 )- 参数:
alpha- 透明度 [0-255]red- 红色值 [0-255]green- 绿色值 [0-255]blue- 蓝色值 [0-255]- 返回:
- argb 颜色值
-
isRGB
public static boolean isRGB(int color) 判断颜色 RGB 是否有效- 参数:
color- rgb color- 返回:
trueyes,falseno
-
isARGB
public static boolean isARGB(int color) 判断颜色 ARGB 是否有效- 参数:
color- argb color- 返回:
trueyes,falseno
-
setAlpha
public static int setAlpha(int color, int alpha) 设置透明度- 参数:
color- argb/rgb coloralpha- 透明度 [0-255]- 返回:
- argb 颜色值
-
setAlpha
public static int setAlpha(int color, float alpha) 设置透明度- 参数:
color- argb/rgb coloralpha- 透明度 [0-255]- 返回:
- argb 颜色值
-
setRed
public static int setRed(int color, int red) 改变颜色值中的红色色值- 参数:
color- argb/rgb colorred- 红色值 [0-255]- 返回:
- argb/rgb 颜色值
-
setRed
public static int setRed(int color, float red) 改变颜色值中的红色色值- 参数:
color- argb/rgb colorred- 红色值 [0-255]- 返回:
- argb/rgb 颜色值
-
setGreen
public static int setGreen(int color, int green) 改变颜色值中的绿色色值- 参数:
color- argb/rgb colorgreen- 绿色值 [0-255]- 返回:
- argb/rgb 颜色值
-
setGreen
public static int setGreen(int color, float green) 改变颜色值中的绿色色值- 参数:
color- argb/rgb colorgreen- 绿色值 [0-255]- 返回:
- argb/rgb 颜色值
-
setBlue
public static int setBlue(int color, int blue) 改变颜色值中的蓝色色值- 参数:
color- argb/rgb colorblue- 蓝色值 [0-255]- 返回:
- argb/rgb 颜色值
-
setBlue
public static int setBlue(int color, float blue) 改变颜色值中的蓝色色值- 参数:
color- argb/rgb colorblue- 蓝色值 [0-255]- 返回:
- argb/rgb 颜色值
-
parseColor
解析颜色字符串, 返回对应的颜色值支持的格式: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'- 参数:
colorStr- argb/rgb color String- 返回:
- argb/rgb 颜色值
-
intToRgbString
颜色值 转换 RGB 颜色字符串- 参数:
colorInt- rgb int color- 返回:
- rgb color String
-
intToArgbString
颜色值 转换 ARGB 颜色字符串- 参数:
colorInt- argb int color- 返回:
- argb color String
-
getRandomColor
public static int getRandomColor()获取随机颜色值- 返回:
- 随机颜色值
-
getRandomColor
public static int getRandomColor(boolean supportAlpha) 获取随机颜色值- 参数:
supportAlpha- 是否支持透明度- 返回:
- argb/rgb 颜色值
-
getRandomColorString
获取随机颜色值字符串- 返回:
- 随机颜色值
-
getRandomColorString
获取随机颜色值字符串- 参数:
supportAlpha- 是否支持透明度- 返回:
- 随机颜色值
-
judgeColorString
判断是否为 ARGB 格式的十六进制颜色, 例如: FF990587- 参数:
colorStr- color String- 返回:
trueyes,falseno
-
setDark
颜色加深 ( 单独修改 RGB 值, 不变动透明度 )- 参数:
colorStr- color StringdarkValue- 加深值- 返回:
- 加深后的颜色值
-
setDark
public static int setDark(int color, int darkValue) 颜色加深 ( 单独修改 RGB 值, 不变动透明度 )- 参数:
color- int colordarkValue- 加深值- 返回:
- 加深后的颜色值
-
setLight
颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )- 参数:
colorStr- color StringlightValue- 变亮 ( 变浅 ) 值- 返回:
- 变亮 ( 变浅 ) 后的颜色值
-
setLight
public static int setLight(int color, int lightValue) 颜色变浅, 变亮 ( 单独修改 RGB 值, 不变动透明度 )- 参数:
color- int colorlightValue- 变亮 ( 变浅 ) 值- 返回:
- 变亮 ( 变浅 ) 后的颜色值
-
setAlphaDark
设置透明度加深- 参数:
colorStr- color StringdarkValue- 加深值- 返回:
- 透明度加深后的颜色值
-
setAlphaDark
public static int setAlphaDark(int color, int darkValue) 设置透明度加深- 参数:
color- int colordarkValue- 加深值- 返回:
- 透明度加深后的颜色值
-
setAlphaLight
设置透明度变浅- 参数:
colorStr- color StringlightValue- 变浅值- 返回:
- 透明度变浅后的颜色值
-
setAlphaLight
public static int setAlphaLight(int color, int lightValue) 设置透明度变浅- 参数:
color- int colorlightValue- 变浅值- 返回:
- 透明度变浅后的颜色值
-
grayLevel
获取灰度值- 参数:
colorStr- color String- 返回:
- 灰度值
-
grayLevel
public static int grayLevel(int color) 获取灰度值- 参数:
color- int color- 返回:
- 灰度值
-
setParser
设置 Color 解析器- 参数:
parser-ColorUtils.ColorInfo.Parser
-
sortGray
灰度值排序- 参数:
lists- 待排序颜色集合
-
sortHUE
HSB ( HSV ) HUE 色相排序- 参数:
lists- 待排序颜色集合
-
sortSaturation
HSB ( HSV ) Saturation 饱和度排序- 参数:
lists- 待排序颜色集合
-
sortBrightness
HSB ( HSV ) Brightness 亮度排序- 参数:
lists- 待排序颜色集合
-
blendColor
使用给定的比例在两种 ARGB 颜色之间进行混合- 参数:
color1- 第一种 ARGB 颜色color2- 第二种 ARGB 颜色ratio- 两种颜色混合比例- 返回:
- 混合后的颜色
-
blendColor
public static int blendColor(int color1, int color2, float ratio) 使用给定的比例在两种 ARGB 颜色之间进行混合android.support.v4.graphics.ColorUtils#blendARGB 混合比: 0.0 将产生 color1 0.5 将产生均匀的混合 1.0 将产生 color2- 参数:
color1- 第一种 ARGB 颜色color2- 第二种 ARGB 颜色ratio- 两种颜色混合比例- 返回:
- 混合后的颜色
-
transitionColor
计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值- 参数:
startColor- 开始颜色值endColor- 结束颜色值ratio- 过渡百分比- 返回:
- 计算后颜色值
-
transitionColor
public static int transitionColor(int startColor, int endColor, float ratio) 计算从 startColor 过渡到 endColor 过程中百分比为 ratio 时的颜色值- 参数:
startColor- 开始颜色值endColor- 结束颜色值ratio- 过渡百分比- 返回:
- 计算后颜色值
-