I\'m creating a DialogFragment to show some help messages regarding my app. Everything works fine besides one thing: There is a black stripe at the top of the window that sh
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;
}
Try easy way
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, 0);
}
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;
}
FragmentManager manager = getSupportFragmentManager();
SettingsDialog sd = new SettingsDialog();
sd.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
sd.show(manager, "settings_dialog");
Set the style to Theme_Holo_Dialog_NoActionBar:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, android.R.style.Theme_Holo_Dialog_NoActionBar);
}
public class LoginDialog extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login_dialog, null);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return view;
}
}