1

How do I set the theme of an alert to one of the standard Android themes? I want to use Holo Dark, since the popup defaults to Holo Light. My code:

        AlertDialog.Builder confirm = new AlertDialog.Builder(this);
        confirm.setTitle("Confirm");
        confirm.setMessage("Confirm and set delay?");
        confirm.setCancelable(false);
        confirm.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    startDelay();
               }
           });
        confirm.setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
               }
           });
        confirm.show();
TiberiumFusion
  • 348
  • 4
  • 17

2 Answers2

8

Theme with v7 library android.support.v7.app.AlertDialog

android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this,R.attr.alertDialogTheme);

Theme with constructer for android.app.AlertDialog

android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this,AlertDialog.THEME_HOLO_LIGHT );

But as per new documentation
This constant(AlertDialog.THEME_HOLO_LIGHT) was deprecated in API level 23. Use Theme_Material_Light_Dialog_Alert .

 android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this,android.R.style.Theme_Material_Light_Dialog_Alert );
Lokesh Tiwari
  • 10,496
  • 3
  • 36
  • 45
2

You can a pass a theme in the constructor.

new AlertDialog.Builder (this, AlertDialog.THEME_HOLO_DARK)
wvdz
  • 16,251
  • 4
  • 53
  • 90