【发布时间】:2015-10-06 15:29:53
【问题描述】:
我试图让 AlertDialog 后面的背景模糊。该过程如下:截取活动的屏幕截图并将其模糊并将其保存到位图中。然后将此位图转换为可绘制对象。然后我使用这行代码renameDialog.getWindow().setBackgroundDrawable(draw);设置警报窗口的可绘制背景
问题是即使我通过指定布局参数来强制某个位置,对话框也只会显示在屏幕顶部。我注意到如果我将setBackgroundDrawable 更改为setBackgroundDrawableResource 并给它一个现有的drawable,那么对话框就会显示在指定的位置。
需要做什么才能使setBackgroundDrawable 可以与对话框的指定位置一起使用?
谢谢!
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();
【问题讨论】:
-
您是否尝试过将背景设置为对话框的最后一个操作?
-
试试这个库:Blur Dialog Fragment
-
@wasyl 是的,我做到了,但没用。我相信问题也与风格有关。
-
@vipul_asri 谢谢,但我不想为此使用库。
标签: android android-alertdialog blur layoutparams