Transparent AlertDialog has black background

后端 未结 4 1858
温柔的废话
温柔的废话 2020-11-27 16:31

I have a custom AlertDialog style that makes the AlertDialog box transparent. It works fine except that when I inflate my desired transparent layo

4条回答
  •  臣服心动
    2020-11-27 17:02

    The problem is that AlertDialog builder is actually not good for designing transparent dialog and will and always have this black background which is actually a Theme for it, instead use the Dialog to create a transparent theme instead.

    sample:

    Dialog alertDialog = new Dialog(this);
    alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    alertDialog.setContentView(R.layout.tabs);
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    alertDialog.show();
    

    Using Dialog does not require any theme manipulation for transparent background so it is basically easy.

提交回复
热议问题