问题描述
我用下面的代码创建了一个 AlertDialog
.出于某种原因,我在 Honeycomb 及更高版本上获得了额外的背景(见图片).代码崩溃适用于蜂窝以下的任何内容.MyCustomDialog
只是 Theme.Dialog
的 API-11 和
Theme.Holo.Dialog
适用于 API-11 及更高版本.
I create a
AlertDialog
with the code below.For some reason I'm getting an extra background (see pic) on Honeycomb and above.The code crashes fine for anything below honeycomb.MyCustomDialog
is simply Theme.Dialog
for < API-11 and Theme.Holo.Dialog
for API-11 and up.
知道为什么我会得到额外的背景吗?
知道为什么它会因 API < 而崩溃.11?如果我删除主题,它就可以正常工作.
更新找出问题 2 的答案.似乎构造函数
AlertDialog.Builder(Context context, int theme)
是在 API 11 中引入的.我的修复只是将行更改为:
Update figured out the answer to Question #2. Seems the constructor
AlertDialog.Builder(Context context, int theme)
was introduced in API 11. My fix was simply to change the line to:
final AlertDialog.Builder builder = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(this) : new AlertDialog.Builder(this,R.style.JumpDialog);
我仍然需要关于问题 1 的帮助
I still need help with Question #1
private Dialog setupKeyBoardDialog() {
if (mContact.getLocaleId() != -1) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.MyCustomDialog);
builder.setTitle("Keyboards");
mKeyboardLayouts = new KeyboardLayoutGroup();
mKeyboardLayouts.layoutNames = new CharSequence[(int) jni.getNumKeyLayouts()];
mKeyboardLayouts.layoutValue = new ArrayList<Integer>();
for (int i = 0; i < jni.getNumKeyLayouts(); i++) {
mKeyboardLayouts.layoutNames[i] = jni.LayoutInfoForIndex(i).getName();
mKeyboardLayouts.layoutValue.add(i, (int) jni.LayoutInfoForIndex(i).getLocale_id());
}
final int selectedItem = mKeyboardLayouts.layoutValue.indexOf(mContact.getLocaleId());
builder.setSingleChoiceItems(mKeyboardLayouts.layoutNames, selectedItem, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
mContact.setLocaleId(mKeyboardLayouts.layoutValue.get(item));
mContactsDB.saveContact(mContact, true);
dialog.dismiss();
initializeSettingsList();
}
});
final AlertDialog dialog = builder.create();
dialog.setButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogBox, int arg1) {
dialogBox.cancel();
}
});
return dialog;
}
return null;
}
推荐答案
找到答案
AlertDialog 在每个主题的静态常量上都有AlertDialog 类,它不采用标准主题.当我替换了
R.style.MyTheme
或android.R.style.Theme_Holo_Dialog
使用AlertDialog.THEME_HOLO_LIGHT
代码刚工作很好.似乎是构造函数
AlertDialog.Builder(Context context, int主题)
是在 API 11 中引入的.我的修复只是改变行至:
AlertDialog has it's on static constants for each theme in theAlertDialog class and it does not take the standard theme. when Ireplaced
R.style.MyTheme
orandroid.R.style.Theme_Holo_Dialog
withAlertDialog.THEME_HOLO_LIGHT
the code worked justfine.Seems the constructor
AlertDialog.Builder(Context context, inttheme)
was introduced in API 11. My fix was simply to change theline to:
final AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
builder = new AlertDialog.Builder(this);
} else {
builder = new AlertDialog.Builder(this,R.style.JumpDialog);
}
这篇关于Android 警报对话框背景问题 API 11+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!