I am trying to have a blurry background behind an AlertDialog. The process goes like the following: take a screenshot of the activity and blur it and save it to a bitmap. Then converting this bitmap to a drawable. Then I set the drawable background of the window of the alert using this line of code renameDialog.getWindow().setBackgroundDrawable(draw);
The issue is that the dialog is only getting shown on the top of the screen even though I am forcing a certain location by specifying a layout parameters. I noticed if I changed setBackgroundDrawable
to setBackgroundDrawableResource
and give it an existing drawable, then the dialog is shown at the specified location.
What needs to be done so that the setBackgroundDrawable
can be used with a specified location to the dialog?
Thanks!
AlertDialog renameDialog = new AlertDialog.Builder(this).create();
LayoutInflater factory = LayoutInflater.from(this);
deleteDialogView = factory.inflate(R.layout.dialog_rename_playlist, null);
//Getting Blurry screenshot to display it behind dialog
Bitmap backgroundScreenshot = Utils.takeScreenShot(PlaylistActivity.this);
Bitmap blurryBackground = Utils.getBlurredBitmap(backgroundScreenshot, 30);
WindowManager.LayoutParams wmlp = renameDialog.getWindow().getAttributes();
wmlp.gravity = Gravity.CENTER_VERTICAL;
wmlp.x= 100;
wmlp.y= 100;
final Drawable draw=new BitmapDrawable(getResources(), blurryBackground);
renameDialog.getWindow().setBackgroundDrawable(draw);
renameDialog.getWindow().setAttributes(wmlp);
renameDialog.setView(deleteDialogView, 0, 0, 0, 0);
renameDialog.show();