【发布时间】:2015-03-30 07:03:36
【问题描述】:
突然间我所有的对话框标题都消失了。我尝试了几部手机(4.4.4 和 4.2.2)进行测试,但似乎仍在发生。
我不确定是什么原因造成的?我正在对我的应用程序进行一些更新(不是任何与对话框相关的),我注意到所有对话框都已更改。我能想到的是,当我进行 gradle 同步或其他操作时,它改变了我的应用程序主题。我使用的 Dialog Fragment 是几个不同的地方,它们都发生了变化。
这是我的一个对话框片段的示例。
我什至尝试过像这样指定样式:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), STYLE_NORMAL);
我该怎么做才能找回我的标题和图标?
一些代码:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), STYLE_NORMAL);
builder.setIcon(R.drawable.password_icon);
builder.setTitle(dialogTitle);
builder.setMessage(dialogMessage);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
onDialogOkClick(dialog);
}
});
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.enterudlcode_dialog, null));
return builder.create();
这是上面屏幕截图的 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/enterudlcode_dialog_editText_panelcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center_horizontal"
android:inputType="numberPassword">
<requestFocus />
</EditText>
<CheckBox
android:id="@+id/enterudlcode_dialog_checkbox_remember_me"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:checked="false"
android:text="Remember Panel Code" />
</LinearLayout>
这是我的应用程序主题/样式文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="LoginFormContainer">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">16dp</item>
</style>
</resources>
【问题讨论】:
-
删除
STYLE_NORMAL -
我添加了
STYLE_NORMAL,希望它能修复它。它以前没有。会再试一次 -
显示您的对话框 XML
-
@Ajeet 我已经添加了它。不确定它的 xml 将如何影响对话框?
-
@Zapnologica 删除 setMessage 并重试。告诉我它是否没有帮助:)
标签: android dialog android-alertdialog android-dialogfragment