Android: Blurring and dimming background windows from dialogs

The android SDK has lots of nice goodies built in to make your applications look sexier. One such feature is the blurring of windows. This effect looks particularly nice if a background window is blurred while a dialog box is shown above which can really make it stand out. Below shows the application such an example; on the left is the default about box (for WordCube Pro) and on the right is with added blur and no dimming.

android blur dim, before, after

android bluring and dimming effect before and after

I am using the AlterDialog.Builder to create my dialog, however this method will work with all kinds of dialog providing you can access it via getWindow.

   dialog = new AlertDialog.Builder(WordCube.this)
   .setPositiveButton(R.string.btn_close, null)

Below shows the code needed to add blur and remove dimming of the background (as I think the blur looks nicer when the background is well lit).

WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();

The blur is simply created using the last line (line 4) which sets a flag for the dialog telling android that we want windows below this one to be blurred. To achieve the dimming, we need to retrieve the layout parameters for the dialog window, set the dim amount to zero, update these parameters with setAttributes (lines 1-3).

Any comments, questions, or improvements please let me know.


  1. Ravi

    One word Thank You. I was trying to do this – your site answered in 5 seconds. Thank you Thank you.

  2. jack

    Is it possible that removing blur, dimming of the background using your technique ?
    I just want a transparent background window of a dialog.

  3. mat

    I haven’t tested it but I think this is how you would do it:

    WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();

    By setting alpha to 0.5 it should make the window 50% transparent. Try it out let me know how it goes…

  4. Chad

    Thanks! People don’t waste 3 hours like I did. You have to SHOW the dialog first or in my case with a custom dialog setContentView() first BEFORE, like so. Or it WONT work.

    SkillMenuView skillMenuView = new SkillMenuView(this);

    WindowManager.LayoutParams lp = getWindow().getAttributes();
    lp.dimAmount = 0.0F;
    lp.screenBrightness = 1.0F;

  5. Matt

    This helped out immensely.

    I tried to override the AlertDialog theme originally and was not having very much success.

  6. Cristian

    It worked like a charmed!

    Thank you so much!

  7. Ken

    mDialog = new ProgressDialog(this); mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);


    WindowManager.LayoutParams lp = mDialog.getWindow().getAttributes();
    lp.dimAmount = 0.0f;

    Doesn’t really work… I even tried to modify the styles.xml file. Please help.

  8. sat

    Valuable information , worked perfectly for the alertDialog.

  9. mcveat

    Thanks. You helped very much.

  10. leonnib4

    Thank you very very much for such precise and fully-working piece of code.

    I also searched for that for minutes and your site just answered me in 4 lines and 5 secondes 🙂


  11. Bill

    I cannot get this to work. Any help is greatly appreciated. It states that “The method getWindow() is undefined for the type AlertDialog.Builder”. Here’s the code I’m using:

    public static void showEula(final boolean accepted, final Activity activity) {
    AlertDialog.Builder eula = new AlertDialog.Builder(activity)

    if (accepted) {
    // If they’ve accepted the EULA allow, show an OK to dismiss.
    new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
    } else {
    // If they haven’t accepted the EULA allow, show accept/decline buttons and exit on
    // decline.
    new android.content.DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
    new android.content.DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
    WindowManager.LayoutParams lp = eula.getWindow().getAttributes();
    lp.dimAmount = 0.0F;


  12. Praveen

    You should create the alertdialog from the builder.
    AlertDialog a = eula.create();;
    and then call a.getwindows().getattribues() on the alert dialog.
    Without showing the alert dialog get window will fail.

  13. SOurabh

    I want to do it on pop up of POPUPWINDOW.I tried but it is not working

  14. Asela

    To dim background you have to set the dim amount as well as the flag
    WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();

  15. Pranay

    How can we do this for a POP-UP WINDOW?

  16. Symbian

    Note that blur is deprecated and on Android ICS you will get black behind for dialog instead of blur.

  17. Jefta

    Is it only works on dialog? i want to use it on inflated view, is there any way to make it?

  18. Igor Ganapolsky

    This wouldn’t work with DialogFragment.

  19. andré

    Very good man!!

  20. Pete Heller

    To: Chad
    THANK YOU for posting your comment. I was just about to give up hope of controlling the dialog’s background.


  21. wizardx95

    how can i add it into “hello world” first app?
    i’m newbie and
    where to add:
    dialog = new AlertDialog.Builder(WordCube.this)
    .setPositiveButton(R.string.btn_close, null)

    and where to add:
    WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();

    and finally main.xml code look like?
    can u help me? i’m newbie
    thank u very much!

  22. Srikanth

    Thanks a lot. You saved me a lot of time. Thank you so much.

  23. abbasalim

    hi, thanks but this not worked in new android api and is deprecated.
    what is best way now?

  24. MADHU

    Thank you

  25. Pratibha

    The above example is for dialogbox i want the same for popup.
    Please help me how to do this

    Thank you

  26. Alexandro

    FLAG_BLUR_BEHIND deprecated and not working anymore!

  27. very nice

  28. Narayan Singh

    Its So Easy ………… Thank you so much!!!!.

  29. تلگرام باز

    thanks for great post .

  30. […] ここ(Android: Blurring and dimming background windows from dialogs)にそれっぽい回答がございました。 […]

  31. […] tomada de Android: el Desenfoque y la atenuación de fondo de las ventanas de diálogo. Estoy teniendo problemas para obtener el contenido en mi cuadro de diálogo desenfoque. Cuando se […]

  32. Prem Suman

    To those still looking for blurring behind dialogs and bottom sheets, I’ve created a custom BlurBottomSheet which is direct child of DialogFragment (Gist here: which has blurred and dimmed background. You can customize it enough and get a dialog instead of BottomSheet!

  33. […] reprise de Android: le Flou et la gradation de fond des fenêtres de dialogue. Je vais avoir du mal à obtenir le contenu sous mon dialogue de flou. Lors de l'appel […]

  34. how to dim the current activity?

    […] I doubt if you could overlay two activities on top of each other. However, in order to achieve the effect that you mentioned, you could use a customized dialog to popup within your main gallery activity, and then set the rest of the screen as blurred, with the use of window manager. For an example of this, you can see:… […]

  35. […] googled for “android blur background” and found this blog post. […]

Leave a Comment

Your email address will not be published. Required fields are marked *