Android的警告对话框背景问题API 11+ [英] Android Alert Dialog Background Issue API 11+

查看:197
本文介绍了Android的警告对话框背景问题API 11+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 AlertDialog 与下面的code。 出于某种原因,我得到一个额外的背景(见PIC)的蜂窝及以上。 在code 崩溃罚款低于蜂窝东西。 MyCustomDialog 简直就是 Theme.Dialog 为< API-11和 Theme.Holo.Dialog 的API-11及以上。

  1. 在任何想法,为什么我得到额外的背景是什么?
  2. 在任何想法,为什么它崩溃的API< 11?它工作正常,如果我删除的主题。

更新想通了,以问题2的答案。似乎在构造 AlertDialog.Builder(上下文的背景下,诠释主题)的API 11.我的修正只是改变行介绍:

 最后AlertDialog.Builder建设者=(的Integer.parseInt(android.os.Build.VERSION.SDK)< 11)?新AlertDialog.Builder(本):新AlertDialog.Builder(这一点,R.style.JumpDialog);
 

我还需要与问题#帮助1

 私人对话setupKeyBoardDialog(){
    如果(mContact.getLocaleId()!=  -  1){
        最后AlertDialog.Builder建设者=新AlertDialog.Builder(这一点,R.style.MyCustomDialog);
        builder.setTitle(键盘);

        mKeyboardLayouts =新KeyboardLayoutGroup();
        mKeyboardLayouts.layoutNames =新的CharSequence [(INT)jni.getNumKeyLayouts()];
        mKeyboardLayouts.layoutValue =新的ArrayList<整数GT;();

        的for(int i = 0; I< jni.getNumKeyLayouts();我++){
            mKeyboardLayouts.layoutNames [I] = jni.LayoutInfoForIndex(ⅰ).getName();
            mKeyboardLayouts.layoutValue.add(ⅰ,(int)的jni.LayoutInfoForIndex(ⅰ).getLocale_id());
        }

        最终诠释将selectedItem = mKeyboardLayouts.layoutValue.indexOf(mContact.getLocaleId());

        builder.setSingleChoiceItems(mKeyboardLayouts.layoutNames,将selectedItem,新DialogInterface.OnClickListener(){
            @覆盖
            公共无效的onClick(DialogInterface对话,诠释项){
                mContact.setLocaleId(mKeyboardLayouts.layoutValue.get(项目));
                mContactsDB.saveContact(mContact,真正的);

                dialog.dismiss();
                initializeSet​​tingsList();
            }
        });

        最后AlertDialog对话框= builder.create();
        dialog.setButton(取消,新DialogInterface.OnClickListener(){
            @覆盖
            公共无效的onClick(DialogInterface DialogBox的,INT ARG1){
                dialogBox.cancel();
            }
        });

        返回对话框;
    }

    返回null;
}
 

解决方案

想出答案

  1. 在AlertDialog有它的静态常量在每个主题 AlertDialog类,并没有采取标准的主题。当我 替换 R.style.MyTheme android.R.style.Theme_Holo_Dialog AlertDialog.THEME_HOLO_LIGHT 中的code的工作只是 罚款。
  2. 好像构造 AlertDialog.Builder(上下文的背景下,INT 主题)的API 11.我的修正只是改变引入 行:

     最后AlertDialog.Builder建设者;
    如果(Build.VERSION.SDK_INT< Build.VERSION_ codeS.HONEYCOMB){
        建设者=新AlertDialog.Builder(本);
    } 其他 {
        建设者=新AlertDialog.Builder(这一点,R.style.JumpDialog);
    }
     

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.

  1. Any idea why I'm getting the extra background?
  2. Any idea why it crashes for API < 11? It works fine if I remove the Theme.

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);

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;
}

解决方案

Figured out the answers

  1. AlertDialog has it's on static constants for each theme in the AlertDialog class and it does not take the standard theme. when I replaced R.style.MyTheme or android.R.style.Theme_Holo_Dialog with AlertDialog.THEME_HOLO_LIGHT the code worked just fine.
  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;
    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+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆