[英]AlertDialog : the background color is not transparent on some devices
I'm showing a dialog in an Activity. 我在Activity中显示一个对话框。
I set the background color to transparent by using this code 我使用此代码将背景颜色设置为透明
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
And the dialog background shows transparent, but problems arise when I test my app on some other device. 对话框背景显示透明,但当我在其他设备上测试我的应用程序时会出现问题。
It shows a white background instead of transparent. 它显示白色背景而不是透明。
I am not getting how the problem can happen by using the same code in different devices. 我不知道在不同的设备中使用相同的代码会如何发生问题。
Here is my code 这是我的代码
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
,您的问题将得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.