Color (@NotNull String colorHex) { boolean isRgba = isRgbaColorHex(colorHex); if (!isRgba && !isRgbColorHex(colorHex)) return null; try { String alpha = isRgba ? colorHex.substring(HEX_COLOR_LENGTH_RGB) : null; String colorHexWithoutAlpha = isRgba ? colorHex.substring(0, HEX_COLOR_LENGTH_RGB) : colorHex; Color color = Color.decode(colorHexWithoutAlpha); if (isRgba) { color = ColorUtil.toAlpha(color, Integer.parseInt(alpha, 16)); } return color; } catch (NumberFormatException ignored) { return null; } }