DialogFragment with clear background (not dimmed)

前端 未结 4 1344
小蘑菇
小蘑菇 2020-11-30 02:01

I\'m trying to get the background of a DialogFragment to be completely clear.

With setting the style item android:windowIsFloating to true

4条回答
  •  离开以前
    2020-11-30 02:32

    Create your own Customized dialog extends with FragmentDailog and override this method

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
    
        //set the dialog to non-modal and disable dim out fragment behind
        Window window = dialog.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        return dialog;
    }
    

    NOTE: This answer works for me in case of DialogFragment and BottomSheetDialogFragment

提交回复
热议问题