ilyamuromets ilyamuromets - 10 days ago 6
Android Question

Ripple effect doesn't work on the FAB

I have simple app with

FloatingActionButton
from support library (24.2.1).

I want to apply ripple effect to it and made the following:

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email"
app:backgroundTint="#f00" //red
app:rippleColor="#fff" //white
/>


Ripple effect works fine when I click on the button. But when I press and move finger over the button border I see that the background button applies the ripple effect but it isn't reset to default drawable when I lift a finger.

Answer

Thanks to @Nur Ilyas for aiming (http://stackoverflow.com/a/40405359/3789575)!

This code works perfectly with my problem.

public class CustomFAB extends FloatingActionButton {

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        boolean result = super.onTouchEvent(ev);
        if (!result) {
            setPressed(false);
        }
        return result;
    }
}