zoukankan      html  css  js  c++  java
  • Android 获取颜色RGB值

    常用获取颜色的方法

    //#FFB6C1转成Int
    int color = Color.parseColor("#FFB6C1") //或者直接写成 0xFFFFB6C1
    
    //ARGB转Int
    int color = Color.argb(255, 255, 255, 255);
    
    //获取color.xml的颜色资源
    int color = getResources().getColor(R.color.red);

    获取颜色RGB值

       public static String toHexEncoding(int color) {
            String R, G, B;
            StringBuffer sb = new StringBuffer();
            R = Integer.toHexString(Color.red(color));
            G = Integer.toHexString(Color.green(color));
            B = Integer.toHexString(Color.blue(color));
            //判断获取到的R,G,B值的长度 如果长度等于1 给R,G,B值的前边添0
            R = R.length() == 1 ? "0" + R : R;
            G = G.length() == 1 ? "0" + G : G;
            B = B.length() == 1 ? "0" + B : B;
            sb.append("0x");
            sb.append(R);
            sb.append(G);
            sb.append(B);
            return sb.toString();
        }

    颜色代码在线转换

  • 相关阅读:
    分分钟搞定Python之排序与列表
    分分钟搞定Python之排序与列表
    联系我
    联系我
    联系我
    联系表单 1_copy
    联系表单 1_copy
    联系表单 1_copy
    联系表单 1
    联系表单 1
  • 原文地址:https://www.cnblogs.com/94xiyang/p/9367202.html
Copyright © 2011-2022 走看看