AlertDialog主题不起作用

时间:2013-04-04 07:13:33

标签: android alertdialog

我的来源

private static final int ALERT_DIALOG = 1;

    @Override
    public void onBackPressed() {
        // buildAlertMessageExit();

        showDialog(ALERT_DIALOG);
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog = null;
        if (id == ALERT_DIALOG) {
            ContextThemeWrapper ctw = new ContextThemeWrapper(this,
                    R.style.AlertDialogCustom);
            AlertDialog.Builder builder = new AlertDialog.Builder(ctw);
            builder.setMessage("Hello World")
                    .setTitle("Alert Dialog")
                    .setIcon(android.R.drawable.ic_dialog_alert)
                    .setCancelable(false)
                    .setPositiveButton("Close",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    dialog.dismiss();
                                }
                            });
            dialog = builder.create();
        }
        if (dialog == null) {
            dialog = super.onCreateDialog(id);
        }
        return dialog;
    }

styles.xml

 <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
     <item name="android:windowBackground">@null</item> 
    <item name="android:windowFrame">@null</item>
   </style>

因此没有主题

enter image description here

1 个答案:

答案 0 :(得分:4)

注意到这一点:

ContextThemeWrapper ctw = new ContextThemeWrapper(this,
                    R.style.AlertDialogCustom);
            AlertDialog.Builder builder = new AlertDialog.Builder(ctw);

AlertDialog.Builder builder = new AlertDialog.Builder(this,
                R.style.AlertDialogCustom_);

But its require MIN API LEVEL 11.

如果您需要支持Android >= 3.0,则可能需要创建custom dialog(而非使用AlertDialog

检查此link以获取更多详细信息。