I want to add focus ripple
effect to whole RadioButton
, but there is something strange is happening to it when I try to use ripple
effect with highlight. In the picture, left is what I get and right is what I want:
background_drawable:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/colorAccent">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
</shape>
</item>
</ripple>
styles.xml
<style name="RadioButtonStyle" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:background">@drawable/radio_button_background</item>
</style>
This happens only If I try to use ripple
effect and not if I try to use only shape
with selector
and state_focused=true
as background. For now my workaround is to use warpper View
class for RadioButton
and set background into it. Is there any way to get background as in the picture but without any additional code? Thanks.
The solution is to set the
button
attribute tonull
and set thedrawableStart
attribute in styles for the radio button:After that focus works as aspected and You can add background to the radio button as You want