关于android:如何使活动背景透明并模糊背景

How to make an activity background transparent and blur the background

当我启动我的应用程序时,它会启动一个Activity,它应该具有透明的标题,并且当前在背景中显示的内容应该是模糊的。

enter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class BlurBuilder {
    private static final float BITMAP_SCALE = 0.4f;
    private static final float BLUR_RADIUS = 7.5f;

    public static Bitmap blur(Context context, 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(context);
        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;
    }
}

有关更多详细信息,请参见此链接

或者您可以使用Blurry

Does anyone has an idea where is the code in android to do that?

有关拍摄应用程序屏幕截图的信息,请参见此链接


我用它来给我的编辑文本背景带来模糊效果,您可以根据自己的喜好对其进行修改,并以不透明的方式玩耍:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8"?><!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:centerColor="#33FFFFFF"
        android:endColor="#33FFFFFF"
        android:gradientRadius="270"
        android:startColor="#33FFFFFF"
        android:type="radial" />
    <corners
        android:bottomLeftRadius="25dp"
        android:bottomRightRadius="25dp"
        android:topLeftRadius="25dp"
        android:topRightRadius="25dp" />
</shape>

或者,您可能对此或此

感兴趣

作为另一种选择,您可以使用一个小的模糊位图并重复它:

1
2
3
4
5
6
7
8
9
    <xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    android:id="@+id/MainLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/backrepeat"
    >

然后准备:

1
2
3
    <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/back"
        android:tileMode="repeat" />