Bouncing off the answer by Jonathan Ellis, in Kotlin you can define a helper function to make the code a bit more idiomatic and easier to read, so you can write this instead:
val colorList = colorStateListOf(
intArrayOf(-android.R.attr.state_enabled) to Color.BLACK,
intArrayOf(android.R.attr.state_enabled) to Color.RED,
)
colorStateListOf
can be implemented like this:
fun colorStateListOf(vararg mapping: Pair<IntArray, Int>): ColorStateList {
val (states, colors) = mapping.unzip()
return ColorStateList(states.toTypedArray(), colors.toIntArray())
}
I also have:
fun colorStateListOf(@ColorInt color: Int): ColorStateList {
return ColorStateList.valueOf(color)
}
So that I can call the same function name, no matter if it's a selector or single color.