Alternative to "FLAG_BLUR_BEHIND" in Android?

23,449

Solution 1

ok , there is probably no alternative that uses the API , unless maybe i've forgetting anything.

i can however use dimming , which is cool too, as written here:

WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();  
lp.dimAmount=0.0f;  
dialog.getWindow().setAttributes(lp);  
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);  

Solution 2

watch out that

WindowManager.LayoutParams.FLAG_BLUR_BEHIND

is deprecated.. (at least at Android 4.0 it leads to a black screen in background...)

Reference (Source): http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html

int FLAG_BLUR_BEHIND This constant is deprecated. Blurring is no longer supported.

public static final int FLAG_BLUR_BEHIND

Since: API Level 1
This constant is deprecated.
Blurring is no longer supported.

Window flag: blur everything behind this window.

Constant Value: 4 (0x00000004)

what a pitty .. :( (was a nice effect ;))

Share:
23,449
android developer
Author by

android developer

Really like to develop Android apps & libraries on my spare time. Github website: https://github.com/AndroidDeveloperLB/ My spare time apps: https://play.google.com/store/apps/developer?id=AndroidDeveloperLB

Updated on January 12, 2020

Comments

  • android developer
    android developer over 4 years

    I can see that when I use the same flag as shown on the API-demos for blurring the background, I get a warning that it's deprecated:

    "The field WindowManager.LayoutParams.FLAG_BLUR_BEHIND is deprecated".

    I've read about it, and I've found that "Blurring is no longer supported".

    Does it mean that it won't work on future versions? Why did they deprecate it? Is there an alternative? I really like this feature.

  • android developer
    android developer almost 12 years
    how come ? it's a cool effect. also , how do you know (in the API website) from which version this constant is deprecated? in addition , what would happen if i use it on android 4?
  • cV2
    cV2 almost 12 years
    if u use it on android 4.0 the background is not blurred, it's straight black, no effect at all, also doesnt look very well, because on all other devices it's nicely blurred ... to your other question, i edited my answer above: look there: )
  • android developer
    android developer almost 12 years
    the link you gave is the API website , which is the one i've read about . they don't say from which version of android this feature is not available ...
  • android developer
    android developer almost 12 years
    another alternative is shown here : youtube.com/… meaning getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEH‌​IND) or use getWindow().setBackground(new ColorDrawable(0x7f000000)
  • cV2
    cV2 almost 12 years
    sry no idea exactly, but first time i realized it was with android 4.0
  • android developer
    android developer almost 12 years
    you know , it's weird that the API website doesn't tell anything about deprecated things . they should add a description of why it's deprecated , alternatives , and from which version it's deprecated.
  • cV2
    cV2 almost 12 years
    hehe ;) yeah definitly, would be much more better :) interesting :) easier :) - each and every thing u mentioned :)
  • shkschneider
    shkschneider over 11 years
    setBackgroundDrawable() not setBackground() at least for me
  • Someone Somewhere
    Someone Somewhere over 11 years
    indeed, the line of code in the Google video is wrong. It should say getWindow().setBackgroundDrawable(new ColorDrawable(0x7000000));
  • Abandoned Cart
    Abandoned Cart almost 11 years
    You can save yourself a few lines with just dialog.getWindow().setDimAmount(0.0f);
  • Léon Pelletier
    Léon Pelletier about 10 years
    Funnier is the fact that iOS 7 currently integrates it as a native functionality.
  • cV2
    cV2 about 10 years
    :( ;=) .... there are several algorithms to create a blurred screenshot and just show it (but much effort and high performance needed :()
  • Gem
    Gem about 8 years
    FLAG_BLUR_BEHIND flag is deprecated in api level 14
  • android developer
    android developer about 8 years
    @Gem Does it mean it doesn't work? I think it still works.