【发布时间】: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