How to create a DialogFragment without title?
Dialog fragment has setStyle method, which should be called before view creation Java Doc. Also style of the dialog can be set with the same method
public static MyDialogFragment newInstance() {
MyDialogFragment mDialogFragment = new MyDialogFragment();
//Set Arguments here if needed for dialog auto recreation on screen rotation
mDialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
return mDialogFragment;
}
Just add this line of code in your HelpDialog.onCreateView(...)
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
This way you're explicitly asking to get a window without title :)
EDIT
As @DataGraham
and @Blundell
pointed out on the comments below, it's safer to add the request for a title-less window in the onCreateDialog()
method instead of onCreateView()
. This way you can prevent ennoying NPE when you're not using your fragment as a Dialog
:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
// request a window without the title
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}