AlertDialog
以下のコードでを作成します。何らかの理由で、ハニカム以上で追加の背景 (写真を参照) を取得しています。コードは、ハニカムよりも下であれば問題
なくクラッシュします。MyCustomDialog
は単にTheme.Dialog
API-11 未満およびTheme.Holo.Dialog
API-11 以降を対象としています。
- 余分な背景を取得している理由はわかりますか?
- API < 11 でクラッシュする理由はありますか? テーマを削除すると正常に動作します。
更新により、質問 2 の答えがわかりました。コンストラクターAlertDialog.Builder(Context context, int theme)
は API 11 で導入されたようです。私の修正は、単に行を次のように変更することでした。
final AlertDialog.Builder builder = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(this) : new AlertDialog.Builder(this,R.style.JumpDialog);
質問 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;
}