1

我的来源

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

样式.xml

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

结果没有主题

在此处输入图像描述

4

1 回答 1

5

插入这个:

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.

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

于 2013-04-04T12:00:22.903 回答