gpt4 book ai didi

java - 对于类型 AlertDialog.Builder 未定义方法 getWindow()

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:44 25 4
gpt4 key购买 nike

想法取自 Android: Blurring and dimming background windows from dialog .我无法使对话框下的内容变得模糊。调用 eula.getWindow() 时收到此错误:

The method getWindow() is undefined for the type AlertDialog.Builder

eula 与主 Activity 中的这段代码一起显示:

    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);

}

最佳答案

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);

请注意,虽然 FLAG_BLUR_BEHIND 常量现在已弃用,但在窗口后面模糊是 no longer supported .因此,您的代码将来可能会中断。

关于java - 对于类型 AlertDialog.Builder 未定义方法 getWindow(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8537518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com