How to create a dialog without a title?

I am creating a DialogFragment to show some help messages related to my application. Everything works just fine, except for one thing: there is a black bar at the top of the window that displays the Dialog dialog box, which I believe is reserved for a name that I don't want to use.

This is especially painful since my custom DialogFragment uses a white background, so the change is too infamous to be left out.

Let me show you this more graphically:

enter image description here

Now the XML code for my DialogFragment looks like this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/holding" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/dialog_fragment_bg" > <!-- Usamos un LinearLayout para que la imagen y el texto esten bien alineados --> <LinearLayout android:id="@+id/confirmationToast" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/confirmationToastText" android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="@string/help_dialog_fragment" android:textColor="#AE0000" android:gravity="center_vertical" /> </LinearLayout> <LinearLayout android:id="@+id/confirmationButtonLL" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal" > <Button android:id="@+id/confirmationDialogButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:layout_marginBottom="60dp" android:background="@drawable/ok_button"> </Button> </LinearLayout> </LinearLayout> </ScrollView> 

And the class code that implements DialogFragment:

 public class HelpDialog extends DialogFragment { public HelpDialog() { // Empty constructor required for DialogFragment } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //Inflate the XML view for the help dialog fragment View view = inflater.inflate(R.layout.help_dialog_fragment, container); TextView text = (TextView)view.findViewById(R.id.confirmationToastText); text.setText(Html.fromHtml(getString(R.string.help_dialog_fragment))); //get the OK button and add a Listener ((Button) view.findViewById(R.id.confirmationDialogButton)).setOnClickListener(new OnClickListener() { public void onClick(View v) { // When button is clicked, call up to owning activity. HelpDialog.this.dismiss(); } }); return view; } } 

And the creation process in the main Office:

 /** * Shows the HelpDialog Fragment */ private void showHelpDialog() { android.support.v4.app.FragmentManager fm = getSupportFragmentManager(); HelpDialog helpDialog = new HelpDialog(); helpDialog.show(fm, "fragment_help"); } 

I really don't know if this answer related to a dialog is suitable, Android: how to create a dialog without a title?

How can I get rid of this header area?

+299
android android-dialogfragment
Mar 07 '13 at 17:10
source share
6 answers

Just add this line of code to your HelpDialog.onCreateView(...)

 getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

This way you explicitly request a window without a title :)


EDIT

As @DataGraham and @Blundell noted the comments below, it is safer to add a query for a window without a title in the onCreateDialog() method instead of onCreateView() . This way you can prevent unnecessary NPE when you are not using your fragment as 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; } 
+517
Mar 07 '13 at 18:54
source share

The dialog fragment has the setStyle method, which should be called before creating the Java Doc view. Also, the dialogue style can be set using 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; } 
+61
May 08 '13 at 19:23
source share
 FragmentManager manager = getSupportFragmentManager(); SettingsDialog sd = new SettingsDialog(); sd.setStyle(DialogFragment.STYLE_NO_TITLE, 0); sd.show(manager, "settings_dialog"); 
+17
Dec 11 '13 at 8:44
source share

Set the Theme_Holo_Dialog_NoActionBar style:

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(STYLE_NORMAL, android.R.style.Theme_Holo_Dialog_NoActionBar); } 
+9
Dec 10 '13 at 12:20
source share

Try the easy way.

 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(STYLE_NO_TITLE, 0); } 
+9
Oct. 21 '15 at 20:07
source share
 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; } } 
+8
Aug 12 '14 at 7:47
source share



All Articles