How to make activity background transparent and blur background

When I launch my application, it launches an Activity , which should have a transparent title, and everything that appears in the background should be blurry.

enter image description here

I can get transparency. But I can’t figure out how to blur the background. For example, if I launch the application from the main screen, then the home screen should be visible, but blurry.

I have an idea to use Framebuffer to get the current data displayed, but how to convert this to a bitmap that I can use to draw the image without saving the image and using the data directly.

I also know that we can take a screenshot by pressing the power and volume buttons. Does anyone have an idea where the android code is for this? My application will have system access.

+6
source share
2 answers

How to blur the background?

You can use RenderScript in the support library

 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; } } 

see this link for more details

Or you can use blurry

Does anyone have an idea where the android code is for this?

To take a screenshot of your application, see this link.

+4
source

I used this to give a blur effect to my text, you can change it to your preference, play with opacity:

 <?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> 

alternatively, you may be interested in this or this

As another alternative, you can use a small blur bitmap and repeat it:

  <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" > 

Then prepare:

  <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/back" android:tileMode="repeat" /> 
+4
source

All Articles