android模糊背景的实现
android上模糊后期已经通用了基本上就是RenderEffect。
为了使用方便简便找到一个合适的库
implementation 'com.github.Dimezis:BlurView:version-2.0.4'
<eightbitlab.com.blurview.BlurView
android:id="@+id/blurView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
....
app:blurOverlayColor="#bbffffff">
<TextView
android:id="@+id/deviceName"
style="xxxx"
.../>
</eightbitlab.com.blurview.BlurView>
简单使用就是设置一个app:blurOverlayColor即可。简单起见,就是
//圆角参数
val viewOutlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(0, 0, view.width, view.height, 4f.dp)
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { //高版本使用模糊,低版本纯半透
//设置模糊度
binding.blurView.setupWith(binding.root, RenderEffectBlur()) // or RenderEffectBlur
//.setFrameClearDrawable(windowBackground) // Optional
.setBlurRadius(12f)
//设置圆角
binding.blurView.outlineProvider = viewOutlineProvider
binding.blurView.clipToOutline = true
} else {
binding.blurView.setBackgroundResource(R.drawable.corner4dp_alpha)
}
//corner4dp_alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:radius="4dp"/>
<solid android:color="#f0FFFFFF"/>
</shape>
但是吧,android上如果底下是recycleView要进行上下滑动,而上一层覆盖blurView,效果挺差的。所以建议那种情况就不要用了。
原文地址:https://blog.csdn.net/jzlhll123/article/details/140118468
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!