How can i add title to this custom dialog??
I have tried like this
public void customDialog()
{
Dialog dialog=new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.string.app_name );
dialog.setContentView(R.layout.dialog_submit);
TextView edit_model=(TextView) dialog.findViewById(R.id.edit_model);
edit_model.setText(android.os.Build.DEVICE);
dialog.show();
}//end of custom dialog function
I have tried to set title like this too..dialog.setTitle("Enter Details");
but this too didn't yielded any result. So how can i set title to this custom dialog??
This is my dialog_submit.xml file used for the custom dialog.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<TextView android:id="@+id/txt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="Name"
android:textStyle="bold"
/>
<EditText android:id="@+id/edit_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_name"
/>
<TextView android:id="@+id/txt_model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_below="@+id/edit_name"
android:text="Phone Model"
/>
<TextView android:id="@+id/edit_model"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_model"
/>
<Button android:id="@+id/but_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_model"
android:text="Cancel"
/>
<Button android:id="@+id/but_submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_model"
android:layout_toRightOf="@+id/but_cancel"
android:text="Submit"
/>
</RelativeLayout>
What you might try, if you still need an answer to this, is an
AlertDialog.Builder
Object. In this Object you can also call thesetMessage("Title")
method, which will set the title in theDialog
you eventually create with this. Moreover, you can also specify apositiveButton
,neutralButton
and anegativeButton
(let's say "Add", "Ok" and "Cancel" in that order, though you can specify your own text).I believe the problem lies in that when you call
Dialog dialog = new Dialog(this)
theonCreateDialog(int id)
is called. But here's the catch: this method is called once and delivers aDialog
which is reused whenever you need a newDialog
. TheDialog
however, can't be edited any more (as far as I know). Well maybe with theonPrepareDialog(int id, Dialog dialog)
method, but I am still trying to get that working myself. My point is, that after creation, you can't edit the User Interface on the Dialog anymore. So the way that does work is by Overriding theonCreateDialog(int id)
in your code, creating anAlertDialog.Builder
(or whatever you are basing yourDialog
on:ProgressDialog
/AlertDialog
/etc.) and setting the title, layout and buttons here. After this, you can call thecreate()
method, which will actually build theDialog
with your settings.This will create a
Dialog
with the title set to "Your Title", which uses the layout you specified, and has one button with the text "Add". Note that the main difference between positive, neutral and negative buttons is that their layout on theDialog
is changed accordingly (positive = left, neutral = middle and negative = right).For more information I would advise you to see the documentation about this.