I am new to android and try to create a simple color picker.
The idea is to have a few filled circles showing a color and the selected one should have an circle around it.
That didn't sound too hard. I draw the circles with <shape>
, create two resources, one with only a filled circle, one with the filled circle and an transparent circle with a solid stroke. Then I created a <selector>
and set this as the background of my <RadioButton>
.
This worked fine for one color, however now I'd like to have the same styles, but with a different color for each <RadioButton>
.
The only solotution I could come up with is to create this triplet of xml-files for each color. This would certainly work, but it strikes me as extremely inelegant.
I tried to access the background of the buttons, but it seems I can only access the <selector>
, not it's children.
I also tried to create a FrameLayout
that would parent the RadioButton
and an ImageView
so the RadioButton
only needs to display the border. This didn't fully work. I could select a RadioButton, but it wouldn't get deselected upon selecting another one.
I guess the best solution is to have a background that can change itself according to the state of the button, just like <selector>
does, but with a more comprehensive way of determining which drawable to use, at least with access to the tag
-Property of the RadioButton
, but I cannot see how to do this.