要解决AlertDialog上的背景模糊问题,可以使用以下方法:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog alertDialog = builder.create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialog.show();
这将使AlertDialog的背景设为透明,以解决背景模糊的问题。
然后,在代码中使用自定义布局创建AlertDialog:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.custom_dialog, null);
builder.setView(view);
AlertDialog alertDialog = builder.create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialog.show();
这将创建一个完全透明的对话框,解决了背景模糊的问题。
AlertDialog.Builder builder = new AlertDialog.Builder(context, android.R.style.Theme_DeviceDefault_Dialog);
AlertDialog alertDialog = builder.create();
alertDialog.show();
这将使用系统主题的AlertDialog样式,通常不会有背景模糊的问题。
请注意,在上面的代码示例中,需要将"context"替换为实际的上下文对象,"R.layout.custom_dialog"替换为自定义布局的资源ID,或者使用其他适合的系统主题样式。