Mohrez khorasani
Mohrez khorasani

Reputation: 11

How to add ripple animation to widget with custom background?

How to implement following hover (Ripple) in android?
I have a linear layout and i want when user touched the layout all widgets in linear layout become lighter.
hover

Upvotes: 0

Views: 242

Answers (1)

Zeus Almighty
Zeus Almighty

Reputation: 175

Create a ripple drawable in res/drawable:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="@color/ripple"
    tools:targetApi="lollipop">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="@color/ripple" />
            <corners android:radius="@dimen/dp_6" />
        </shape>
    </item>
</ripple>

Set this drawable to the button foreground:

android:foreground = "@drawable/bg_btn_ripple_animation"

You can modify the ripple drawable as per your liking.

Upvotes: 1

Related Questions