AlertDialog:背景颜色在某些设备上不透明

AlertDialog : the background color is not transparent on some devices

我正在 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,您的问题就会得到解决。