Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding ripple effect to already custom button

I'm trying to add ripple effect to a custom button. But the only solution I found is adding a background which I have already done for achieving rounded corners for that button. Now I want to add the ripple effect. This is how my button tag looks so far:

<Button
    android:text="PLAY"
    android:id="@+id/button"
    android:textSize="20dp"
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:background="@drawable/roundedbutton"
    android:onClick="gotomainpage"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="200dp" />
like image 681
Usman Noor Avatar asked Dec 10 '22 12:12

Usman Noor


2 Answers

use this code in your button

android:foreground="?attr/selectableItemBackground"
like image 111
Hamid Goodarzi Avatar answered Dec 13 '22 00:12

Hamid Goodarzi


Easy

1. Creating an Ripple Drawable Contains the Backgound Shape

<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?colorControlHighlight">         //defaul ripple color

    <item>
        <shape                                //the background shape when it's not being click
            android:shape="rectangle">

            <solid
                android:color="@color/colorPrimary" />

            <corners
                android:radius="32dp" />

        </shape>

    </item>

</ripple>

2. Applying the Drawable to the Button and REMOVE THE SHADOW

<Button
    style="?borderlessButtonStyle"              //remove the default shadow
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_weight="1"
    android:background="@drawable/background_button"        //here
    android:text="Sign up"
    android:textAllCaps="false"
    android:textColor="@android:color/white" />

enter image description here

like image 39
Sam Chen Avatar answered Dec 13 '22 00:12

Sam Chen