最近遇到了水波纹问题,解决的方案有两种
1. android:background="@drawable/selecterDrawable"
2. android:foreground="?selectableItemBackground"
首先最外层的LinearLayout 设置 android:background="@drawable/selecterDrawable",此时要求子View必须是透明的,
使用 android:foreground="?selectableItemBackground",发现没有水波纹的效果
查看View源码中,其中有一段一段
case R.styleable.View_foreground:
if (targetSdkVersion >= VERSION_CODES.M || this instanceof FrameLayout) {
setForeground(a.getDrawable(attr));
}
break;
从上面代码可以看出,foreground
属性只有在以下两种情况下生效:
1. 安卓M版本(6.0)及以上
2. FrameLayout本身及其子类
补充:关于android:background 和 android:foreground 补充
https://www.jianshu.com/p/b5ecd39ed494