简体   繁体   中英

AlertDialog : the background color is not transparent on some devices

I'm showing a dialog in an 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 ,您的问题将得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM