我正在使用显示正常波纹的按钮,但是如果更改为无边界波纹,则该按钮将无法正常工作。按钮在布局内部的位置应该在哪里,以使此涟漪始终起作用?现在,它位于相对布局内部,并且位于其他相对布局内部,可以容纳图像,按钮和其他内容。

最佳答案

我做了一个图书馆,使您的问题易于解决

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"/>


然后用java

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

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


这是文档:https://github.com/xgc1986/RippleViews/blob/master/docs/RippleDrawableHelper.md

编辑

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));


如果可行,是因为它为一个视图创建了RippleDrawable,但是您可以将此可绘制对象分配给另一个视图,然后按b1视图时,它会显示相对于v2的波纹

关于android - 波纹和selectableItemBackgroundBorderless,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28618662/

10-10 00:59