How to change the background color around a DialogFragment?

前端 未结 8 1838
时光取名叫无心
时光取名叫无心 2020-11-29 01:59

I\'m building a custom DialogFragment. The dialog layout is set to my_dialog.xml, but how can I modify the color around the dialog (the transparent

8条回答
  •  自闭症患者
    2020-11-29 02:24

    I had to set android:windowIsFloating to false and android:windowBackground to my custom color in the dialog style:

    styles.xml

    
    
        
    
    
    

    MyDialogFragment

    public class MyDialogFragment extends DialogFragment {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialog);
        }
    }
    

提交回复
热议问题