本文介紹了如何為自定義對話框添加標題?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何為這個自定義對話框添加標題??
How can i add title to this custom dialog??
我試過這樣
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");
但這也沒有產生任何結果.那么如何設置這個自定義對話框的標題呢?
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??
這是我用于自定義對話框的 dialog_submit.xml 文件.
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>
推薦答案
使用你的一些片段:
public void customDialog() {
Dialog dialog=new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.setContentView(R.layout.dialog_submit);
dialog.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
dialog.show();
}
res/layout/custom_title.xml
res/layout/custom_title.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a custom title"/>
這篇關于如何為自定義對話框添加標題?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!