ColorUtils { @NonNull public static String convertToString(@ColorInt int color) { StringBuilder hex = new StringBuilder("#"); hex.append(Integer.toHexString(color)); while (hex.length() < 9) { hex.append("0"); } return hex.toString(); }  @NonNull static String convertToString(@ColorInt int color);  }
@Test public void testCovertColorString() { assertEquals("#ff000000", ColorUtils.convertToString(Color.BLACK)); assertEquals("#ff0000ff", ColorUtils.convertToString(Color.BLUE)); assertEquals("#ffff0000", ColorUtils.convertToString(Color.RED)); assertEquals("#ff00ff00", ColorUtils.convertToString(Color.GREEN)); assertEquals("#00000000", ColorUtils.convertToString(Color.TRANSPARENT)); }