将透明度的百分比转化为十六进制的字符串

public static String percent2HexStr(double percent) {
    try {
        double j = Math.round(percent * 100) / 100.0d;
        int alpha = (int) Math.round(j * 255);
        String hex = Integer.toHexString(alpha).toUpperCase();
        if (hex.length() == 1) {
            hex = "0" + hex;
        }

// Log.d("hex", "percent:" + percent + "|" + "hex:" + hex);
return hex;
} catch (Exception e) {
// do nothing
}
}

你可能感兴趣的:(将透明度的百分比转化为十六进制的字符串)