取自Android: Blurring and dimming background windows from dialog的想法。我無法讓我的對話框中的內容模糊。當調用eula.getWindow()我收到此錯誤:對於AlertDialog.Builder類型,未定義getWindow()方法
The method getWindow() is undefined for the type AlertDialog.Builder
的EULA將顯示來自主要活動這段代碼:
EulaHelper.showEula(false, this);
任何幫助是極大的讚賞。
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);
}
儘管兩個答案都是正確的, alextsc的答案更符合我的代碼。謝謝你的快速反應。 – 2011-12-16 17:17:52
不用擔心,我們完全在同一時間做了我們的答案:) – Guillaume 2011-12-16 19:23:45