我正在 Activity 中显示一个对话框。
我使用此代码将背景颜色设置为透明
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
对话框背景显示透明,但当我在其他设备上测试我的应用程序时出现问题。
它显示白色背景而不是透明背景。
我不明白在不同设备中使用相同的代码如何会发生问题。
这是我的代码
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.update_client, null);
****** some code*******
dialogBuilder.setView(dialogView);
alertDialog = dialogBuilder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
}
最佳答案
尝试使用Dialog
而不是AlertDialog
,您的问题将会得到解决。
关于java - 警报对话框 : the background color is not transparent on some devices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37438181/