android - 波纹和 selectableItemBackgroundBorderless

标签 android background ripple selectable borderless

我使用的是显示正常波纹的按钮,但如果我更改为无边界波纹则不起作用。按钮在布局内部的位置应该在哪里才能始终使这种波纹起作用?它现在位于相对布局内部,位于内容图像、按钮和其他内容的其他相对布局之上。

最佳答案

我做了一个库让你的问题很容易解决

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/

相关文章:

android - 磨损项目-attr 'android:windowSwipeToDismiss'

php - Android - 检查 MySQL 中的 SELECT 语句是否返回值

android - 按键图标不起作用

html - 实际 CSS 响应背景不响应(?)

iphone - 如何在 iPhone 应用程序中为 pdf 文件添加背景颜色

android - 如何为按钮添加带渐变的波纹效果?

cordova - Visual Studio 多设备项目在 Ripple 中间歇性地挂起

java - Android 寻呼机适配器,onClick

ios - 推送的 ViewController 显示未分配的背景颜色

android - 使用 LiveData 的波纹效果/点击动画