A custom ripple click effect for Android
- Define
RippleView
in your xml file and wrap the view that you want to appy your ripple effect on.
...
<vakili.ramin.customview.views.RippleView
android:id="@+id/myRippleView"
android:layout_centerInParent="true"
app:rippleDuration="200"
app:cornerRadius="200"
app:maxRippleDuration="2000"
app:rippleColor="#55555555"
app:highlightColor="#457b7b7b"
android:gravity="center"
android:layout_width="120dp"
android:layout_height="48dp">
<TextView
android:text="Ripple"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</vakili.ramin.customview.views.RippleView>
...
- In your code after finding the reference
setRippleListener
to it and add your code there.
...
RippleView rippleView = (RippleView) findViewById(R.id.myRippleView);
rippleView.setRippleListener(new RippleView.RippleListener() {
@Override
public void onRippleCompleted() {
Toast.makeText(MainActivity.this, "Do Something", Toast.LENGTH_SHORT).show();
}
});
...