1

I use Dialog Fragment I extend it

public class DocumentLibrarySelectionFragment extends DialogFragment 

I am not sure how to dismiss this dialog when the user presses outside it (I show this dialog inside my activity). I went through other related questions, but couldn't find complete answer, for example this How to dismiss a DialogFragment when pressing outside the dialog? here, where to add this lines of code in the first answer? Thanks.

Community
  • 1
  • 1
Mediha
  • 610
  • 2
  • 9
  • 22

1 Answers1

4

In onCreateView, you can add DialogFragment.getDialog().setCanceledOnTouchOutside(true);

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ...
    getDialog().setCanceledOnTouchOutside(true);
    ... 
}
Gilad Green
  • 35,761
  • 7
  • 54
  • 89
Sushil
  • 7,865
  • 2
  • 35
  • 66
  • To add this method in my DialogFragment implementation or? I have @Override public Dialog onCreateDialog(Bundle savedInstanceState) { method only in my fragment implementation? – Mediha Aug 11 '13 at 23:49
  • As Blackbelt said (https://stackoverflow.com/a/16480564/6444297), instead of 'getDialog().setCancelable(false);' you have to use directly 'setCancelable(false);' – Alireza Noorali Oct 09 '17 at 08:38