如何添加标题自定义对话框? [英] How to add title to the custom Dialog?

查看:128
本文介绍了如何添加标题自定义对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何我可以添加标题到这个自定义对话框??

我已经试过像这样

 公共无效customDialog()
 {
  对话的对话=新的对话框(本);
  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();
 } //定制对话框功能的结束

我试图设置标题这样太.. dialog.setTitle(输入详细信息); 但这也并没有取得任何结果。所以,我怎么可以设置标题,这个自定义对话框??

这是用于自定义对话框我dialog_submit.xml文件。

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
          机器人:ID =@ + ID / layout_root
          机器人:方向=垂直
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =FILL_PARENT
          机器人:填充=10dp
          >
  < TextView的机器人:ID =@ + ID / txt_name
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:文字颜色=#FFF
          机器人:文字=姓名
          机器人:文字样式=大胆
          />
  < EditText上机器人:ID =@ + ID / edit_name
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =WRAP_CONTENT
          机器人:layout_below =@ + ID / txt_name
          />
< TextView的机器人:ID =@ + ID / txt_model
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:文字颜色=#FFF
          机器人:layout_below =@ + ID / edit_name
          机器人:文字=手机型号
          />
< TextView的机器人:ID =@ + ID / edit_model
          机器人:layout_width =FILL_PARENT
          机器人:layout_height =WRAP_CONTENT
          机器人:layout_below =@ + ID / txt_model
          /><按钮机器人:ID =@ + ID / but_cancel
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:layout_below =@ + ID / edit_model
          机器人:文字=取消
          />
<按钮机器人:ID =@ + ID / but_submit
          机器人:layout_width =WRAP_CONTENT
          机器人:layout_height =WRAP_CONTENT
          机器人:layout_below =@ + ID / edit_model
          机器人:layout_toRightOf =@ + ID / but_cancel
          机器人:文字=提交
          />
< / RelativeLayout的>


解决方案

使用你的一些片断:

 公共无效customDialog(){
    对话的对话=新的对话框(本);
    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 /布局/ custom_title.xml

 < TextView中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=这是一个自定义标题/>

Hi 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>

解决方案

Using some of your snippet:

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

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆