android颜色Color

1.常量颜色

Color.BLACK~Color.TRANSPARENT

	@ColorInt public static final int BLACK       = 0xFF000000; //黑色
    @ColorInt public static final int DKGRAY      = 0xFF444444; //灰色
    @ColorInt public static final int GRAY        = 0xFF888888; //灰色
    @ColorInt public static final int LTGRAY      = 0xFFCCCCCC; //灰色
    @ColorInt public static final int WHITE       = 0xFFFFFFFF; //白色
    @ColorInt public static final int RED         = 0xFFFF0000; //红色
    @ColorInt public static final int GREEN       = 0xFF00FF00; //绿色
    @ColorInt public static final int BLUE        = 0xFF0000FF; //蓝色
    @ColorInt public static final int YELLOW      = 0xFFFFFF00; //黄色
    @ColorInt public static final int CYAN        = 0xFF00FFFF; //青色
    @ColorInt public static final int MAGENTA     = 0xFFFF00FF; //洋红色
    @ColorInt public static final int TRANSPARENT = 0;		    //透明的

2.构造颜色

2.1 带透明度的颜色

Color.``_argb_``(alpha``,``red``,``green``,``blue)``;
源码:

  public static int argb(
            @IntRange(from = 0, to = 255) int alpha,
            @IntRange(from = 0, to = 255) int red,
            @IntRange(from = 0, to = 255) int green,
            @IntRange(from = 0, to = 255) int blue) {
        return (alpha << 24) | (red << 16) | (green << 8) | blue;
    }
	@ColorInt
    public static int argb(float alpha, float red, float green, float blue) {
        return ((int) (alpha * 255.0f + 0.5f) << 24) |
               ((int) (red   * 255.0f + 0.5f) << 16) |
               ((int) (green * 255.0f + 0.5f) <<  8) |
                (int) (blue  * 255.0f + 0.5f);
    }

2.2 不带透明度的颜色

Color.``rgb(float red, float green, float blue)
源码:

 	@ColorInt
    public static int rgb(
            @IntRange(from = 0, to = 255) int red,
            @IntRange(from = 0, to = 255) int green,
            @IntRange(from = 0, to = 255) int blue) {
        return 0xff000000 | (red << 16) | (green << 8) | blue;
    }
	@ColorInt
    public static int rgb(float red, float green, float blue) {
        return 0xff000000 |
               ((int) (red   * 255.0f + 0.5f) << 16) |
               ((int) (green * 255.0f + 0.5f) <<  8) |
                (int) (blue  * 255.0f + 0.5f);
    }
发布了21 篇原创文章 · 获赞 1 · 访问量 871

猜你喜欢

转载自blog.csdn.net/qq_33401954/article/details/105246481