Android AlertDialog in Activity Dialog.Theme



我正在尝试创建一个警报对话框,如下所示:

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,我可以在片段上创建AlertDialog,但我似乎无法打开弹出窗口上的AlertDialog

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

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

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

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

最新更新