Mediha
Mediha

Reputation: 760

Dismiss Dialog Fragment when pressed outside

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.

Upvotes: 1

Views: 3361

Answers (1)

Sushil
Sushil

Reputation: 8488

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ...
    getDialog().setCanceledOnTouchOutside(true);
    ... 
}

Upvotes: 4

Related Questions