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
This class was deprecated in API level 28. Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle.
DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
Show activity on this post. tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
This worked for me.
myDialogFragment.setCancelable(false);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With