我如何添加標題到這個自定義對話框?如何將標題添加到自定義對話框?
我已經試過這樣
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
我試圖設置標題這樣太.. dialog.setTitle("Enter Details");
但這也並沒有取得任何結果。那麼我如何設置標題到這個自定義對話框?
這是我用於定製對話框的dialog_submit.xml文件。
<?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>
我已經在上面提到它,dialog.setTitle(「???」)不是任何結果。 – Shijilal 2011-01-31 15:32:15
@Shijilal:再看看Cristian的答案 - 他用int而不是CharSequence來設置標題。確保你也嘗試了這種方法。它可能無法正常工作,但請確保您嘗試了兩個setTitle()選項。 – McStretch 2011-01-31 15:40:08
@McStretch我試過..但它不工作.dialog.SetTitle將工作,如果我刪除dialog.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);如果我刪除這個,那麼標題和第一個視圖(ie.name)之間有很大差距,這就是爲什麼我想要與FEATURE.CUSTOM_TITLE – Shijilal 2011-01-31 15:50:30