Android 活动背景模糊,不知道活动背后是什么

Android 活动背景模糊,不知道活动背后是什么,android,css,android-activity,background-image,Android,Css,Android Activity,Background Image,我有一个活动,每次打开手机都会跳起来 我希望它的背景是模糊的,所以任何活动应该打开后,我的,将是模糊的。但我不知道后面应该有什么活动 因为它不是我的应用程序中的活动,可能来自任何应用程序 所以我不能使用模糊我在这里使用的上一个活动的方法 我创建了一个模糊生成器,如下所述 像这样 import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import andro

我有一个活动,每次打开手机都会跳起来

我希望它的背景是模糊的,所以任何活动应该打开后,我的,将是模糊的。但我不知道后面应该有什么活动

因为它不是我的应用程序中的活动,可能来自任何应用程序

所以我不能使用模糊我在这里使用的上一个活动的方法

我创建了一个模糊生成器,如下所述

像这样

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
import android.renderscript.ScriptIntrinsicBlur;
import android.view.View;
public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.4f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(View v) {
        return blur(v.getContext(), getScreenshot(v));
    }

    public static Bitmap blur(Context ctx, Bitmap image) {
        int width = Math.round(image.getWidth() * BITMAP_SCALE);
        int height = Math.round(image.getHeight() * BITMAP_SCALE);

        Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false);
        Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap);

        RenderScript rs = RenderScript.create(ctx);
        ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
        Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap);
        Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap);
        theIntrinsic.setRadius(BLUR_RADIUS);
        theIntrinsic.setInput(tmpIn);
        theIntrinsic.forEach(tmpOut);
        tmpOut.copyTo(outputBitmap);

        return outputBitmap;
    }

    private static Bitmap getScreenshot(View v) {
        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        v.draw(c);
        return b;
    }
}
但我不知道如何在我的活动的onCreate中使用它


谢谢

在您的
onCreate()中使用此选项:

对于片段:

final Activity activity = getActivity();
final View content = activity.findViewById(android.R.id.content).getRootView();
    if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(activity.getResources(), image));
}
final View content = findViewById(android.R.id.content).getRootView();
if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(getResources(), image));
}
对于活动:

final Activity activity = getActivity();
final View content = activity.findViewById(android.R.id.content).getRootView();
    if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(activity.getResources(), image));
}
final View content = findViewById(android.R.id.content).getRootView();
if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(getResources(), image));
}
编辑:

final Activity activity = getActivity();
final View content = activity.findViewById(android.R.id.content).getRootView();
    if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(activity.getResources(), image));
}
final View content = findViewById(android.R.id.content).getRootView();
if (content.getWidth() > 0) {
        Bitmap image = BlurBuilder.blur(content);
        content.setBackground(new BitmapDrawable(getResources(), image));
}
onCreate()
中,添加以下内容以解决模糊问题:

new CountDownTimer(1, 1) {
public void onTick(long millisUntilFinished) {
        }

public void onFinish() {
            final View content = findViewById(android.R.id.content).getRootView();
            if (content.getWidth() > 0) {
                Bitmap image = BlurBuilder.blur(content);
                content.setBackground(new BitmapDrawable(getResources(), image));
            }

        }
}.start();

相信我,它是有效的,你是如何使用代码的@MumfordwizI在我的活动的onCreate中添加了Jumps,现在每次它都应该跳转Crassesi就是按照你说的方式使用的。如果你用一个片段来模糊它,效果会很好,现在我在Activty上尝试,但它并没有按照你喜欢的方式工作