How to make it so that when you create a dialog, the dialog title is displayed based on the layout file?

Class code of my dialogue:

 import android.app.Dialog; import android.app.DialogFragment; import android.os.Bundle; import android.view.*; import android.widget.EditText; import net.squirrel.postar.client.R; public class DialogSaveTrack extends android.app.DialogFragment implements View.OnClickListener { private DialogueResultListener listener; private EditText eDescription; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { listener = (DialogueResultListener) getActivity(); Dialog dialog = getDialog(); dialog.setTitle(getText(R.string.dialog_add_description)); setStyle(DialogFragment.STYLE_NORMAL , 0); View v = inflater.inflate(R.layout.dialog_add_description, null); eDescription = (EditText) v.findViewById(R.id.eDescription); v.findViewById(R.id.bContinue).setOnClickListener(this); v.findViewById(R.id.bCancel).setOnClickListener(this); return v; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.bCancel: dismiss(); break; case R.id.bContinue: listener.onDialogResult(eDescription.getText().toString()); dismiss(); break; } } 

}

XML layout file:

 <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/eDescription"/> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="160dp" android:layout_height="wrap_content" android:text="Continue" android:id="@+id/bContinue"/> <Button android:layout_width="160dp" android:layout_height="wrap_content" android:text="Cancel" android:id="@+id/bCancel"/> </LinearLayout> 

Result:

Dialog using the layout file
When you create a dialogue, using the "builder" dialogue is created normally - with a title.

Also tried:

  setStyle(DialogFragment.STYLE_NORMAL , 0); 

I setTitle through various options for setting setTitle in various functions of dialog handlers, searched the Internet, looked at code examples, but did not find the answer. And like the default headers are ...
Please who knows or who has some suggestions tell me.

    1 answer 1

    Add style

     <style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog"> <item name="android:windowNoTitle">false</item> </style> 

    And use it in the dialogue:

     setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog); 
    • Added setStyle to onCreate and the corresponding theme, thanks helped. - Orfey