java - 警报对话框 : the background color is not transparent on some devices

标签 java android android-alertdialog

我正在 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/

相关文章:

Android:通过应用程序使用 Wifi 连接

java - Android 可滚动 AlertDialog 以编程方式

android - 自定义具有单选列表项的对话框

java - 记录输入流

java - ArrayList.get(int index) 和 ArrayAdapter.getItem(int position) 方法有什么区别?

java - 调用 startActivityForResult 时应用程序崩溃

android - AlertDialog 按钮未包装在 Lollipop 中

Java Linux 从 PrinterJob 打印空白页

android - 从 Azure DevOps 部署到 Google Play 商店时出现错误 "APK specifies a version code that has already been used.."

android - 理解如何使用数据库 SQLite 的问题