Android ripple for button not working

2.3k Views Asked by At

The ripple effect I have given to the background of the button is not working.It just switches the color.The device version is 5.1.1.Please help me!!!

ripple.xml:

<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/white"> <!-- ripple color -->

    <item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->

</ripple>
3

There are 3 best solutions below

3
On

Have you tried like this

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:text="New Button" />

But here you cant change ripple effect color

0
On

Here's an example on how to set the normal background color when using ripple tag.

<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@android:color/white"> <!-- ripple color -->
    <item android:id="@android:id/background">
      <shape android:shape="rectangle">
        <solid android:color="@android:color/holo_blue_bright" /> <!-- normal color -->
      </shape>
    </item>
</ripple>
0
On

The proper way to do is like this -

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="#66ef5350"
    > <!-- ripple color -->
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="#66ef5350" />
            <corners android:radius="2dp"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#ef5350" />
            <corners android:radius="2dp"/>
        </shape>

    </item>

</ripple>

You can change the color as per your requirements.