'Android - Setting RadioButton dot with setButtonDrawable() doesn't work
Simple question, perplexing problem.
I am making a custom dot indicator for an android RadioButton that subclasses AppCompatRadioButton. I just want to change the dot indicator not the whole background. It seems like setButtonDrawable() should do the trick...
class McRadioButton @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : AppCompatRadioButton(context, attrs)
{
init {
setButtonDrawable(R.drawable.mc_radio_button)
invalidate()
requestLayout()
}
}
mc_radio_button.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Shapes are just examples to illustrate the problem -->
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:state_enabled="true" android:state_checked="true" >
<shape android:shape="oval">
<solid android:color="@android:color/holo_red_dark"/>
</shape>
</item>
<item android:state_enabled="true" android:state_checked="false">
<shape android:shape="oval">
<solid android:color="@android:color/holo_blue_bright"/>
</shape>
</item>
<item android:state_enabled="false" android:state_checked="true">
<shape android:shape="oval">
<solid android:color="@android:color/holo_green_light"/>
</shape>
</item>
<item android:state_enabled="false" android:state_checked="false">
<shape android:shape="oval">
<solid android:color="@android:color/holo_orange_light"/>
</shape>
</item>
</selector>
When I use my McRadioButtons inside a RadioGroup I only get the android:text I added to the McRadioButton xml instance. I dont see the dot buttons at all.
Again, setting the background is not what I want. Doing so shows large colored ovals under the text. I just want to change the dot indicators. Also, I dont want to merely change the dot color as it does in the above example. I can use a tint to do that. My actual dot will be more complex. But if I get this working then I can do the rest. How do i set the RadioButton dot via xml drawables? Thanks
setCompoundDrawablesWithIntrinsicBounds(R.drawable.mc_radio_button,0,0,0)
does nothing at all.
This should be simple. What am I doing wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
