Closed wardenlzr closed 1 year ago
Sorry, I'm not sure what you mean. Could you elaborate?
Sorry,My English is not good. I think the answer is this Create a rounded drawable, as usual, set it as a background. And do blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND); blurView.setClipToOutline(true);
But final Drawable windowBackground = getWindow().getDecorView().getBackground(); Log.i(TAG, "windowBackground." + windowBackground); RoundDrawable roundDrawable = new RoundDrawable(getResources(), drawable2Bitmap(windowBackground)); roundDrawable.setRadius(30f); binding.bv.setupWith(((ViewGroup) getWindow().getDecorView())) .setFrameClearDrawable(roundDrawable);
private Bitmap drawable2Bitmap(Drawable drawable) { if (drawable == null) { return null; }
if (drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
try {
Bitmap.Config config =
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
Bitmap bitmap;
//颜色Drawable
if (drawable instanceof ColorDrawable) {
//宽为2, 高为2 ??
bitmap = Bitmap.createBitmap(2, 2, config);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), config);
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
//将 drawable 的内容绘制到 bitmap的canvas 上面去.
drawable.draw(canvas);
return bitmap;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
I set these, but the fillet does not take effect
final Drawable windowBackground = getWindow().getDecorView().getBackground(); Log.i(TAG, "windowBackground." + windowBackground); // RoundDrawable roundDrawable = new RoundDrawable(getResources(), drawable2Bitmap(windowBackground)); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ex_bg); Drawable roundDrawable = new RoundDrawable(bitmap); binding.bv.setupWith(((ViewGroup) getWindow().getDecorView())) .setFrameClearDrawable(roundDrawable); binding.iv.setImageDrawable(roundDrawable);
I'm sure roundDrawable is OK
I still don't understand. Is the problem that you can't set rounded corners?
blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
blurView.setClipToOutline(true);
Should do the job with a proper rounded corner Drawable.
Or is the problem that setFrameClearDrawable
doesn't work with this drawable? (Why is it rounded though?)
Some screenshots of expected and actual results might be helpful
How to get a round corner BlurView?
blurView.setBackgroundDrawable(roundDrawable);
blurView.setOutlineProvider(ViewOutlineProvider.BACKGROUND);
blurView.setClipToOutline(true);
Did that solve your issue?
yes thanks
blurOverlayColorOnly one property can be configured