alorma
01/11/2022, 4:47 PMColor
?Kirill Grouchnikov
01/11/2022, 4:54 PMColor.toArgb
will give you an "encoded" integer, and then you can do "#%08X".format(argbInt)
on itKirill Grouchnikov
01/11/2022, 5:03 PMString.format
is not in common, but rather only available for jvm at the moment - https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/format.htmlephemient
01/11/2022, 5:20 PM"#" + argbInt.toUInt().toString(radix = 16).padStart(8, '0')
in common, although ideally we'd have a common function for this https://youtrack.jetbrains.com/issue/KT-50309alorma
01/11/2022, 5:26 PMalorma
01/11/2022, 5:26 PMColton Idle
01/11/2022, 5:26 PMval textColor =
Integer.toHexString(colorValue.toArgb())
.padStart(8, '0')
.toUpperCase(Locale.ROOT)
.removeRange(0, 2)
val transparencyValue =
if (shouldShowTransparencyValue)
Integer.toHexString(colorValue.toArgb())
.padStart(8, '0')
.toUpperCase(Locale.ROOT)
.take(2)
.getTransparencyValue()
else ""
Colton Idle
01/11/2022, 5:27 PM/** Helper to get a human readable alpha percentage from a 2 char hex code */
private fun String.getTransparencyValue(): String {
return (this.toInt(16) / 255F * 100).roundToInt().toString() + "%"
}
ephemient
01/11/2022, 5:41 PMargbInt.and(0xffffff).toString(radix = 16).padStart(6, '0')
to mask off the alphaAlbert Chang
01/11/2022, 5:51 PM"#%06X".format(color.toArgb() and 0xFFFFFF)
.Colton Idle
01/11/2022, 5:52 PMalorma
01/11/2022, 6:04 PMColton Idle
01/11/2022, 6:11 PMephemient
01/11/2022, 6:20 PM.format()
functions are all JVM-only, I was providing non-JVM variants since that was brought up by Kirillephemient
01/11/2022, 6:21 PMKirill Grouchnikov
01/11/2022, 6:29 PMephemient
01/11/2022, 6:46 PM