从Android颜色转换为HTML颜色

时间:2018-07-29 01:32:27

标签: java android html colors

我想知道如何完成转换:

我已经检查了以下说明:

 int color= ((ColorDrawable)  dialog1.getButton(AlertDialog.BUTTON_POSITIVE).getBackground()).getColor();

在某些设备中给出结果color = -12434878,检查该颜色是否等于HTML颜色#424242。

但是,关键是我看不到从一种转换到另一种的方法,也没有找到任何对此的参考。

这怎么办?

1 个答案:

答案 0 :(得分:1)

将整数转换为十六进制字符串

Integer intColor = -12434878;
String hexColor = "#" + Integer.toHexString(intColor).substring(2);