How to make an activity background transparent and blur the background
当我启动我的应用程序时,它会启动一个
我能够获得透明度。但是我不知道如何使背景模糊。例如,如果我从主屏幕启动应用程序,则主屏幕应该可见但被模糊掉。
我有一个使用Framebuffer来获取当前显示数据的想法,但是如何将其转换为位图,我可以用它来绘制图像而不保存图像并直接使用数据。
我也知道我们可以通过按电源和音量按钮来截屏。有谁知道android中的代码在哪里执行此操作?我的应用程序将具有系统访问权限。
how to blur the background?
您可以使用支持库
中的
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" /> |