When Android Studio converts from Java to Kotlin, it often converts numbers that were supposed to be of colors.
So, it creates something like:
var someColor = -0x555556
The safe way to find what color this is, is to use Integer.toHexString(), which would result in 0xffaaaaaa for this case.
After I do this, the IDE has a tiny preview of the color on the side, so it helps me read it in both ARGB format and visually:
This is a bit tricky for an inspection, so maybe offer it by default only to places that have the @ColorInt annotation, and an option to expand it even for places that the value doesn't have it.
Please offer such an inspection, and auto-add "0x" and ".toInt()" if needed (IDE says it's an Int already), and if ".toInt()" isn't needed, add the type of the field instead. Or maybe always add the type.
This will make sure that if we change the value with some mistake, it won't change the type so easily to Long type instead.
When Android Studio converts from Java to Kotlin, it often converts numbers that were supposed to be of colors.
So, it creates something like:
The safe way to find what color this is, is to use
Integer.toHexString()
, which would result in0xffaaaaaa
for this case.After I do this, the IDE has a tiny preview of the color on the side, so it helps me read it in both ARGB format and visually:
This is a bit tricky for an inspection, so maybe offer it by default only to places that have the
@ColorInt
annotation, and an option to expand it even for places that the value doesn't have it.Please offer such an inspection, and auto-add "0x" and ".toInt()" if needed (IDE says it's an Int already), and if ".toInt()" isn't needed, add the type of the field instead. Or maybe always add the type. This will make sure that if we change the value with some mistake, it won't change the type so easily to
Long
type instead.