Rémy DAVID
Rémy DAVID

Reputation: 4401

How to make DialogFragment modal?

I have a DialogFragment :

public static class CharacteristicDialog extends DialogFragment {
        int mNum;

        static CharacteristicDialog newInstance(int num) {
            CharacteristicDialog f = new CharacteristicDialog();            
            Bundle args = new Bundle();
            args.putInt("num", num);
            f.setArguments(args);
            return f;
        }

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mNum = getArguments().getInt("num");
            setStyle(STYLE_NO_INPUT, 0);        
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.characteristic_dialog, container, false);
            v.setOnClickListener(new OnClickListener() {                
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

I create it in my main Fragment like this :

        DialogFragment newFragment = CharacteristicDialog.newInstance(v.getId());
        newFragment.setShowsDialog(true);
        newFragment.show(getFragmentManager(), "dialog");   

It shows well, but it is not modal (I can click on the sides and make actions on my main Fragment behind the dialog).

How do I make it modal ?

Thanks

Upvotes: 10

Views: 18818

Answers (2)

Amit Garg
Amit Garg

Reputation: 561

This worked for me.

myDialogFragment.setCancelable(false);

Upvotes: 21

ashakirov
ashakirov

Reputation: 12360

Just change STYLE_NO_INPUT то STYLE_NORMAL into your setStyle() method. For more info about DialogFragment styles and themes take look at docs: http://developer.android.com/reference/android/app/DialogFragment.html

Upvotes: 4

Related Questions