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.
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) .setTitle(WordCube.this.getResources().getString(R.string.app_name)) .setMessage(s) .setIcon(R.drawable.logo) .setPositiveButton(R.string.btn_close, null) .show();
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(); lp.dimAmount=0.0f; dialog.getWindow().setAttributes(lp); dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
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.