Ripple and selectableItemBackgroundBorderless

3.5k views Asked by At

I am using a button that show the normal ripple, but if I change to the borderless ripple is not working. Where should be the position of the button inside of the layout to get always this ripple working? It is now inside of relative layout and over other relative layout that content images, buttons and other things.

1

There are 1 answers

3
xgc1986 On BEST ANSWER

I made a library that makes your problem easy to solve

https://github.com/xgc1986/RippleViews

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btn1"
    android:background:"the color of the button that you want, that important for your case"
    android:text="Default android button"/>

and then with java

View b1 = findViewById(R.id.btn1);

b1.setBackground(RippleDrawableHelper.createRippleDrawable(b1, rippleColor));

here is the doc: https://github.com/xgc1986/RippleViews/blob/master/docs/RippleDrawableHelper.md

edit

View b1 = findViewById(R.id.btn1);
// this may work
View v2 = findViewById(R.id.parent); //the are where the ripple effect extends
//change the view you send in the function

b1.setBackground(RippleDrawableHelper.createRippleDrawable(v2, rippleColor));

If this works, is because it creates a RippleDrawable for a view, but then you can assign this drawable to another view, then when you press the b1 view, it shows the ripple relative to v2