@Nullable private String convertRGBToHex(String svgValue){
  String result=null;
  String functionValue=svgValue.trim();
  functionValue=svgValue.substring(1,functionValue.length() - 1);
  String[] numbers=functionValue.split(",");
  if (numbers.length != 3) {
    return null;
  }
  int[] color=new int[3];
  for (int i=0; i < 3; i++) {
    String number=numbers[i];
    number=number.trim();
    if (number.endsWith("%")) {
      float value=Float.parseFloat(number.substring(0,number.length() - 1));
      color[i]=clamp((int)(value * 255.0f / 100.0f),0,255);
    }
 else {
      int value=Integer.parseInt(number);
      color[i]=clamp(value,0,255);
    }
  }
  StringBuilder builder=new StringBuilder();
  builder.append("#");
  for (int i=0; i < 3; i++) {
    builder.append(String.format("%02X",color[i]));
  }
  result=builder.toString();
  assert result.length() == 7;
  return result;
}

@ Nullable private String convertRGBToHex ( String svgValue ) { String result = null ; String functionValue = svgValue . trim ( ) ; functionValue = svgValue . substring ( 1 , functionValue . length ( ) - 1 ) ; String [ ] numbers = functionValue . split ( "," ) ; if ( numbers . length != 3 ) { return null ; } int [ ] color = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { String number = numbers [ i ] ; number = number . trim ( ) ; if ( number . endsWith ( "%" ) ) { float value = Float . parseFloat ( number . substring ( 0 , number . length ( ) - 1 ) ) ; color [ i ] = clamp ( ( int ) ( value * 255.0f / 100.0f ) , 0 , 255 ) ; } else { int value = Integer . parseInt ( number ) ; color [ i ] = clamp ( value , 0 , 255 ) ; } } StringBuilder builder = new StringBuilder ( ) ; builder . append ( "#" ) ; for ( int i = 0 ; i < 3 ; i ++ ) { builder . append ( String . format ( "%02X" , color [ i ] ) ) ; } result = builder . toString ( ) ; assert result . length ( ) == 7 ; return result ; }
svg allows using rgb ( int , int , int ) or rgb ( float % , float % , float % ) to represent a color , but android doesn ' t . therefore , we need to convert them into # rrggbb format .
