如何使用java模糊覆盖层后面的内容?

问题描述 投票:0回答:0

我有一个布局,可以使用 Context.LAYOUT_INFLATER_SERVICE 在其他应用程序之上公开。但无论我如何搜索,我都找不到一种方法来向用户模糊此视图下的内容。

这就是我想要的: I want to blur the behind content that I marked with red

我用来显示布局的代码:

public class OverlayManager2 {
    private final Context context;
    private final View mView;
    private final WindowManager.LayoutParams mParams;
    private final WindowManager mWindowManager;


    @RequiresApi(api = Build.VERSION_CODES.O)
    @SuppressLint("InflateParams")
    public OverlayManager2(Context context) {
        this.context = context;

        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                PixelFormat.TRANSLUCENT
        );

        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mView = layoutInflater.inflate(R.layout.pin_activity, null);

        mParams.gravity = Gravity.CENTER;
        mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    }



    public void open() {
        try {
            if (mView.getWindowToken() == null) {
                if (mView.getParent() == null) {
                    mWindowManager.addView(mView, mParams);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

我尝试过的一些库只是模糊了位图/图像或视图对象的内容,但它们并没有完全按照我想要的方式执行,或者我失败了(如果您愿意,您可以看一下): https://github.com/CameraKit/blurkit-android

https://github.com/Dimezis/BlurView

https://github.com/wasabeef/Blurry

我看到有人建议使用 opengl 来做到这一点,但我找不到任何关于如何做到这一点的信息。 如果 flutter 可以做到的话,我准备将我的项目与 flutter 合并。

注意:我的目标是 SDK 29 (Android 10),因此我无法使用此功能:https://source.android.com/docs/core/display/window-blurs

java android overlay blur
© www.soinside.com 2019 - 2024. All rights reserved.