Android Blur View (Blur Background Behind the View)

How to Blur A View

This can be achieved in following steps

  1. Extract the background image of LinearLayout by cropping
    background Image.
  2. Now extend LinearLayout Class.

  3. Override OnDraw(Canvas mCanvas) method.

  4. Create two methods in your Custom LinearLayout Class 1.
    DrawBitmap 2. DrawColor.

  5. First call the DrawBitmap function by giving the offset you got from
    ViewPager to background image so that image moves when the use swipe
    the screen.

  6. Finally draw the color with your transparency level

I hope this will solve your problem.

Sample Code for this

View Background Blur

How to set the blur level of a view background

Android doesn't provide this functionality for UI elements as iOS does. It's not part of the UI rendering engine and to obtain these kind of effects you need to use third-party libraries which will essentially take a snapshot of the drawing cache, reduce its size for a faster processing and then put the generated bitmap into a view.

Here are some example libraries:

  • BlurrView
  • Blurry

Please bear in mind that this will have a serious performance hit on mid-low end phones.

Dim and Blur Background Behind Fragment Android

As stated in the comment the FLAG_BLUR_BEHIND was not working with the frame layout I was using.

I instead decided to just change the foreground of the parent

// Dim the background
// Where mainFrameLayout is as FrameLayout
mainFrameLayout.getForeground().setAlpha(220);

And when you would like to remove the "dim" effect

// Remove dim background color
mainFrameLayout.getForeground().setAlpha(0);

How to achieve blur/frost/fibrancy background effect on views (NOT ON IMAGES) like on the Instagram app

Using a library would be the easiest way to achieve this, check out this one:

https://github.com/mmin18/RealtimeBlurView



Related Topics



Leave a reply



Submit