Transparent AlertDialog has black background

后端 未结 4 1856
温柔的废话
温柔的废话 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 16:46

    Those who are having still problem creating custom transparent dialog or alert dialog, can use this combination. I also wanted to show custom background this is what worked for me.

    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    

    example:-

    /**
     * alert dialog
     */
    
        public class ToolTipView extends AlertDialog {
    
            public ToolTipView(@NonNull Context context) {
                super(context);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            }
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.dialog_tool_tip_view);
            }
    
        }
    

提交回复
热议问题