Transparent background in ImageButton with ripple effect? Transparent background in ImageButton with ripple effect? xml xml

Transparent background in ImageButton with ripple effect?


If android:background="?attr/selectableItemBackground" this works than I believe this answer should solve your problem:

https://stackoverflow.com/a/28087443/2534007


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>


To have a transparent background with ripple effect, the background Drawable needs to be a rippleDrawable, which can be transparent. Set it up programmatically like this.

var mask = new android.graphics.drawable.GradientDrawable();mask.setShape(android.graphics.drawable.GradientDrawable.RECTANGLE);mask.setColor(0xFF000000); // the color is irrelevant here, only the alphamask.setCornerRadius(5); // you can have a rounded corner for the effectvar rippleColorLst = android.content.res.ColorStateList.valueOf(    android.graphics.Color.argb(255,50,150,255) // set the color of the ripple effect);// aaaandvar ripple = new android.graphics.drawable.RippleDrawable(rippleColorLst,null,mask);yourImageButton.setBackground(ripple);

(Sorry for the JavaScript/NativeScript code, hope everyone can understand it)