活动Dialog.Theme中的Android AlertDialog [英] Android AlertDialog in Activity Dialog.Theme
问题描述
我试图像这样创建一个AlertDialog:
I am trying to create an AlertDialog like so:
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
的弹出窗口的主题.托管弹出窗口的Activity扩展了Fragment
,我可以在片段上创建AlertDialog
,但似乎无法在弹出窗口上打开AlertDialog
.
I have the theme for the pop up that extends Activity
. And the Activity that hosts the pop up extends Fragment
, I am able to create AlertDialog
s on the fragment, but I can't seem to open the AlertDialog
on the pop up.
<activity
android:name=".Activties.InventoryDescription"
android:theme="@android:style/Theme.Dialog" />
<activity
推荐答案
在样式资源中检查用于该Activity的主题,并将父主题更改为Theme.AppCompat.Light I.e
Check the theme you using for that Activity in style resource and change the parent theme to Theme.AppCompat.Light I.e
或
从清单中的活动中删除此行
remove this line from your activity in your manifest
android:theme ="@ android:style/Theme.Dialog"
android:theme="@android:style/Theme.Dialog"
这篇关于活动Dialog.Theme中的Android AlertDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!