如题,例如用 #FFFFFF  生成一个 Color 对象

解决方案 »

  1.   

    public Color getColor(String col){
        if(col.length()==7){
         return new Color(Integer.parseInt(col.substring(1,3),16),Integer.parseInt(col.substring(3,5),16),Integer.parseInt(col.substring(5,7),16));
        }
        return null;
    }
      

  2.   

    对了,输入的是如: #FFFF00之类的,用Integer.parseInt(col.substring(1,3),16),方法把16进制转换成10进制。运用Color(int r, int g, int b, int a) 构造方法
      

  3.   

    还有就是FFEE00那么FF代表红;EE代表绿;00代表蓝