Implementing Ripple Effects for Android Buttons
For rectangular buttons, use the selectableItemBackground attribute in the foreground to apply a default ripple effect.
<TextView
android:id="@+id/btn_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#06CD5D"
android:foreground="?selectableItemBackground"
android:text="Submit" />
When using a custom rounded background, the ripple effect may not match the buton's shape. To create a rounded button with a matching ripple, define a ripple drawable.
Create a shape drawable for the button background:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#06CD5D" />
<corners android:radius="25dp" />
</shape>
Define a ripple drawable that references the shape:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#22000000">
<item android:drawable="@drawable/rounded_button_background" />
</ripple>
Apply the ripple drawable as the button's background:
<TextView
android:id="@+id/btn_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_rounded_button"
android:text="Action" />
This approach ensures the ripple effect conforms to the button's rounded corners, porviding a consistent visual feedback during user interaction.