我想在我的libGDX项目中显示“确认退出” Holo对话框。这是我的代码:

@Override
public void onBackPressed() {
    AlertDialog.Builder bld;

    if (android.os.Build.VERSION.SDK_INT <= 10) {
        //With default theme looks perfect:
        bld = new AlertDialog.Builder(AndroidLauncher.this);
    } else {
        //With Holo theme appears the double Dialog:
        bld = new AlertDialog.Builder(AndroidLauncher.this, android.R.style.Theme_Holo_Dialog_MinWidth);
    }

    bld.setIcon(R.drawable.ic_launcher);
    bld.setTitle("Exit");
    bld.setMessage("Are you sure you want to exit?");
    bld.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); }
    });
    bld.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) { finish(); }
    });
    bld.setCancelable(false);
    bld.create().show();
}


该对话框有效,但是带有Holo主题的背景看起来很丑。

以下是非全息主题的结果:



Holo主题的丑陋结果:



如何显示没有丑陋的“双对话框”的Holo对话框?谢谢!

最佳答案

代替

bld = new AlertDialog.Builder(AndroidLauncher.this, android.R.style.Theme_Holo_Dialog_MinWidth);

采用

bld = new AlertDialog.Builder(new ContextThemeWrapper(AndroidLauncher.this, android.R.style.Theme_Holo_Dialog_MinWidth));

10-07 20:03