Transparent background in ImageButton with ripple effect?
12,390
Solution 1
If android:background="?attr/selectableItemBackground"
this works than I believe this answer should solve your problem:
https://stackoverflow.com/a/28087443/2534007
Solution 2
Create your own RippleDrawable
and you need to use mask for the Ripple if you're going to use transparent background.
<!-- A red ripple masked against an opaque rectangle. -->
<ripple android:color="#ffff0000">
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
Related videos on Youtube
Author by
Confuse
Updated on June 15, 2022Comments
-
Confuse almost 2 years
I want to programmatically remove the grey background in ImageButton. I tried many method of removing it like -
imageButton.setBackgroundDrawable(null);
but on implementing them, I don't get the ripple effect on the ImageButton on touch. (No highlighting on touch).
Is there any way to remove the background but preserve the ripple effect or highlight.
-
rds over 8 yearsPossible duplicate of How to set background highlight to a LinearLayout?
-
-
tskulbru almost 8 yearsOr even better,
android:background="?attr/selectableItemBackgroundBorderless"
-
Someone Somewhere over 6 years
<ripple> requires API level 21 (current min is 17)
all the good stuff is obviously going to be useful in a few years when users have upgraded... -
Warpzit almost 6 yearsThis will crash on some devices.