【问题标题】:Android AlertDialog in Activity Dialog.ThemeActivity Dialog.Theme 中的 Android AlertDialog
【发布时间】:2017-08-27 23:31:53
【问题描述】:

我正在尝试像这样创建一个 AlertDialog:

Context context = AttributeDescription.this;
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Add Extra");
final EditText base = new EditText(builder.getContext());
final EditText value = new EditText(builder.getContext());
base.setHint("Name");
value.setHint("Value");
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
base.setInputType(InputType.TYPE_CLASS_TEXT);
value.setInputType(InputType.TYPE_CLASS_TEXT);
layout.addView(base);
layout.addView(value);
builder.setView(layout);
builder.setMessage("")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int id) {

         }
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        // User cancelled the dialog
        }
});
// Create the AlertDialog object and return it
AlertDialog dialog = builder.create();
dialog.show();

我不断收到You need to use a Theme.AppCompat theme (or descendant) with this activity.

我的清单是:

android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme"

我有扩展Activity 的弹出窗口的主题。并且托管弹出窗口的活动扩展了Fragment,我可以在片段上创建AlertDialogs,但我似乎无法在弹出窗口上打开AlertDialog

<activity
   android:name=".Activties.InventoryDescription"
   android:theme="@android:style/Theme.Dialog" />
<activity

【问题讨论】:

    标签: android android-fragments android-alertdialog


    【解决方案1】:

    在样式资源中检查您用于该活动的主题并将父主题更改为 Theme.AppCompat.Light I.e

    或者

    从清单中的活动中删除此行

    android:theme="@android:style/Theme.Dialog"

    【讨论】:

    • 是的,这可行,但我如何使 Activity 看起来像 Theme.Dialog 以便它成为一个弹出窗口?
    • 检查这个会有帮助:stackoverflow.com/questions/35834481/…
    • SO 链接好运吗?
    • 您实际上已经解决了大概 8 到 10 个小时我试图解决这个问题的问题!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 2011-06-26
    • 1970-01-01
    相关资源
    最近更新 更多