How to Install AlertDialog Theme

How to customize the notification theme to one of the standard Android themes? I want to use Holo Dark, since the popup is by default related to Holo Light. My code is:

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(); 
+1
source share
2 answers

You can pass the theme in the constructor.

 new AlertDialog.Builder (this, AlertDialog.THEME_HOLO_DARK) 
+2
source

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 constructor for android.app.AlertDialog

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

But according to the new documentation
This constant (AlertDialog.THEME_HOLO_LIGHT) is deprecated at 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 ); 
+4
source

Source: https://habr.com/ru/post/927696/


All Articles