我使用的是显示正常波纹的按钮,但如果我更改为无边界波纹则不起作用。按钮在布局内部的位置应该在哪里才能始终使这种波纹起作用?它现在位于相对布局内部,位于内容图像、按钮和其他内容的其他相对布局之上。
最佳答案
我做了一个库让你的问题很容易解决
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));
如果这行得通,是因为它为一个 View 创建了一个 RippleDrawable,但是你可以将这个 drawable 分配给另一个 View ,然后当你按下 b1 View 时,它会显示相对于 v2 的波纹
关于android - 波纹和 selectableItemBackgroundBorderless,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28618662/