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);
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值