In Android, RED (in Java) is defined as
@ColorInt public static final int RED = 0xFFFF0000;
When we assign to the value as below (in Kotlin), all good.
val value: Int = Color.RED
However when I replace Color.RED
with 0xFFFF0000;
val value: Int = 0xFFFF0000
It will complaint The integer literal does not conform to the expected type Int
. How could I workaround it that I could still write in the ARGB format?
Note
I know if we converted to signed Int as below, all works
val value: Int = -0x10000
But that will be too hard for me to recognize the color format value (i.e the FFFF0000 is referring to ARGB format).
val value: Int = 0xFFFF0000.toInt()
I suggest you use Color.parseColor:
val color: Int = Color.parseColor("FFFF0000")
User contributions licensed under CC BY-SA 3.0