Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ripple drawable in xml not working

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>
like image 853
Simeon Schaub Avatar asked Mar 18 '23 01:03

Simeon Schaub


2 Answers

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>
like image 122
alanv Avatar answered Mar 25 '23 07:03

alanv


<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>

like image 38
Vie Avatar answered Mar 25 '23 07:03

Vie