Toni Alvarez
Toni Alvarez

Reputation: 1032

Android Dialog with Holo theme with libGDX looks weird

I want to show a "confirm exit" Holo Dialog in my libGDX project. This is my code:

@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();
}

The Dialog works, but with the Holo theme appears with an ugly background.

This are the results, with a non-Holo theme:

http://i.imgur.com/XlCFTd4.jpg

And the ugly result with Holo theme:

http://i.imgur.com/NEfMsMy.png

How can I show a Holo Dialog without the ugly "double Dialog"? Thanks!

Upvotes: 2

Views: 874

Answers (1)

Sash_KP
Sash_KP

Reputation: 5591

instead of

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

use

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

Upvotes: 1

Related Questions