Android imagebutton ripple effect

rubmz picture rubmz · Dec 15, 2016 · Viewed 9k times · Source

Okay, so I understood ripple effect is only available LOLLIPOP and up. But, still, when setting up my ImageButton, I fail to get a nice ripple effect that would work like a "regular" Button, just show an image instead (and transparent bg)...

I added AppCompat v7 and put the second layout in my drawable/layout-v21 folder, which has the following button in it:

<ImageButton
    android:id="@+id/forward"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="15dp"
    android:scaleType="fitCenter"
    android:height="15dp"
    android:padding="25dp"
    style="@style/Widget.AppCompat.ImageButton"
    android:src="@drawable/forwardplay" />

But the background is grey and the ripple (grey too) cannot be customised.

So, if I would only have a nice ripple drawable to put in my drawable-v21 that would be great, and I could reference it from the background property of the ImageButton. The thing is I cannot find the original android Ripple effect (I have a Samsung S6 phone, is it Samsung's theme ?)

Would love if anyone could share their working drawable.

Thanks!

Answer

EED  picture EED · Dec 16, 2016

Try this, definitely it should work:

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@android:drawable/YOUR_BUTTON_SOURCE"
    android:background="?attr/selectableItemBackgroundBorderless"
/>