如何添加自定义对话框的标题? [英] How to add title to the custom Dialog?
本文介绍了如何添加自定义对话框的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加此自定义对话框的标题?
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"/>
这篇关于如何添加自定义对话框的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文