Custom item states for android selectors
-
03-10-2019 - |
Question
I see examples of selectors using android states like 'selected' to define style. Here a simplified example:
<selector>
<item android:state_selected="true" android:drawable="@color/transparent" />
<item android:drawable="@drawable/listitem_normal" />
</selector>
So, my question is: Can I define and use my own state instead of
android:state_selected="true"
My goal is to color shapes based on an integer value, like simple version of this heatmap:
Solution
Take a look onto LevelList and LevelListDrawable, it looks like the drawable is what you need.
OTHER TIPS
What you originally wanted can be done with custom boolean attributes.
You can see a coded example here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow