Rémy DAVID Rémy DAVID - 1 month ago 27
Android Question

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

Answer

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

Comments