I'm trying to find a color by its name in an string-array of resources. It is now currently working but this is the last warning in my project and I want to finish him. is there an equivalent in kotlin?
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val text = spinner.selectedItem.toString()
textView.text = text
val textNS = text.replace("\\s".toRegex(), "")
color = textNS
val desiredColor = resources.getColor(resources.getIdentifier(textNS, "color", packageName))
card_view.setCardBackgroundColor(desiredColor)
}
And This is a sample of the string arrays. I have two because I display the name and the color separately
<string-array name="choosableColors">
<item name="White">@color/White</item>
<item name="Ivory">@color/Ivory</item>
<item name="LightYellow">@color/LightYellow</item>
</string-array>
<string-array name="choosableColorsNames">
<item name="White">White</item>
<item name="Ivory">Ivory</item>
<item name="LightYellow">Light Yellow</item>
</string-array>
I just want not to have a deprecated function.
Thanks in advance!!