Rémy DAVID Rémy DAVID - 2 months ago 67
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);
return f;

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

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

I create it in my main Fragment like this :

DialogFragment newFragment = CharacteristicDialog.newInstance(v.getId());
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 ?



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