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>
Share:
12,390

Related videos on Youtube

Confuse
Author by

Confuse

Updated on June 15, 2022

Comments

  • Confuse
    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.

  • tskulbru
    tskulbru almost 8 years
    Or even better, android:background="?attr/selectableItemBackgroundBorderless‌​"
  • Someone Somewhere
    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
    Warpzit almost 6 years
    This will crash on some devices.