Dialog.setTitle不显示标题 [英] Dialog.setTitle not showing a title
本文介绍了Dialog.setTitle不显示标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向对话框中添加自定义标题,但是,每当我运行应用程序时,它都不会显示标题.
I am trying to add a custom title to my Dialog, however whenever I run my application it doesn't show a title.
我创建对话框的代码是
final Dialog passwordDialog = new Dialog(this);
passwordDialog.setContentView(R.layout.admin_password_dialog);
passwordDialog.setTitle("Enter An Administrative Password");
passwordDialog.show();
我的布局文件是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_confirmPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/edit_adminPassword"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/confirmPassword"/>
<EditText
android:id="@+id/edit_adminPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:inputType="textPassword"/>
这就是我要得到的
有什么我想念的吗?
推荐答案
您应该这样定义自己的样式:
you should define your style like this:
<style name="Dialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">false</item>
<item name="android:windowIsFloating">true</item>
</style>
,然后将此样式传递给Dialog的构造器
and then pass this style to the constructor of the Dialog
final Dialog passwordDialog = new Dialog(this,R.style.Dialog);
这篇关于Dialog.setTitle不显示标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文