Bil*_*ote 8 java android blur android-alertdialog
从Android获取的想法:从对话框模糊和调暗背景窗口.我无法将对话框下的内容弄糊涂.调用eula.getWindow()时收到此错误:
对于AlertDialog.Builder类型,方法getWindow()未定义
eula与主要活动的代码一起显示:
EulaHelper.showEula(false, this);
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏.
public static void showEula(final boolean accepted, final FragmentActivity activity) {
AlertDialog.Builder eula = new AlertDialog.Builder(activity)
.setTitle(R.string.eula_title)
.setIcon(android.R.drawable.ic_dialog_info)
.setMessage(activity.getString(R.raw.eula))
.setCancelable(accepted);
if (accepted) {
// If they've accepted the EULA allow, show an OK to dismiss.
eula.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
} else {
// If they haven't accepted the EULA allow, show accept/decline buttons and exit on
// decline.
eula
.setPositiveButton(R.string.accept,
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setAcceptedEula(activity);
dialog.dismiss();
}
})
.setNegativeButton(R.string.decline,
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
activity.finish();
}
});
}
eula.show();
WindowManager.LayoutParams lp = eula.getWindow().getAttributes();
lp.dimAmount = 0.0F;
eula.getWindow().setAttributes(lp);
eula.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
}
Run Code Online (Sandbox Code Playgroud)
小智 15
getWindow()是对话框类的方法,而不是对话框构建器的方法.你的代码应该是这样的:
AlertDialog dlg = eula.show();
WindowManager.LayoutParams lp = dlg.getWindow().getAttributes();
lp.dimAmount = 0.0F;
dlg.getWindow().setAttributes(lp);
dlg.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Run Code Online (Sandbox Code Playgroud)
请注意,虽然FLAG_BLUR_BEHIND现在不推荐使用常量,但不再支持在窗口后面模糊.因此,您的代码将来可能会中断.
eula是构建器,而不是对话框本身.尝试:
final AlertDialog eulaDialog = eula.create();
eulaDialog.show();
WindowManager.LayoutParams lp = eulaDialog.getWindow().getAttributes();
lp.dimAmount = 0.0F;
eulaDialog.getWindow().setAttributes(lp);
eulaDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11236 次 |
| 最近记录: |