How can I change default black dim background “color” (not the amount of dim) of Dialog?

后端 未结 6 1019
野的像风
野的像风 2020-12-05 07:37

\"enter

(This is a random image of showing a Dialog found on the Internet

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 08:22

    This is a workaround but it's not really a pure solution because background touch is disabled and should be configured manually.

    First, set custom dialog theme like this.

    styles.xml

    
    

    Setting windowIsFloating to false forces Dialog view to be expanded to full screen. Setting windowBackground to transparent removes default black dim background under Dialog. windowNoTitle option gets rid of the upper title bar.

    CustomDialog.java

    Apply the theme and construct your custom_dialog view as follows.

    public HTCustomDialog(Context context) {
        super(context, R.style.CustomDialogTheme);
        setContentView(R.layout.custom_dialog);
    }
    

    custom_dialog.xml

    
    
        
    
    
    

    Now that CustomDialog view is a full-screen view, set background of your root layout to whatever color you'd like.

    Sample result

    I mosaiced the result a bit.

    Result

提交回复
热议问题