I'm stuck with a problem: I have an xml drawable that I wanna use as background for a radiobutton, but the ripple effect isn't working. Can anyone help me with that?
My xml for the background:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#8bc34a" >
<item>
<selector>
<item android:drawable="@drawable/tb_checked" android:state_checked="true"></item>
<item android:drawable="@drawable/transparent"></item>
</selector>
</item>
</ripple>
If you want to show an unbounded ripple above or below additional content, use a <layer-list>
container to stack them and don't put any content inside the <ripple>
element.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<ripple android:color="#8bc34a" />
</item>
<item>
<selector>
<item android:drawable="@drawable/tb_checked"
android:state_checked="true" />
<item android:drawable="@drawable/transparent" />
</selector>
</item>
</layer-list>
<RadioButton
android:layout_width="100dp"
android:layout_height="wrap_content"
android:padding="@dimen/activity_horizontal_margin"
android:text="Choice 1"
android:gravity="center"
android:background="@drawable/button_choice_white"
android:button="@null"/>
In the v1-drawable add the background drawable with ripple
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="?attr/colorAccent" />
</shape>
</item>
<item>
<selector>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="?attr/colorAccent"/>
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle">
<solid android:color="?attr/colorAccent"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/button_choice_background"/>
</shape>
</item>
</selector>
</item>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With