Problems with AlertDialog

I am creating an AlertDialog. If you create it like this:

AlertDialog.Builder builder = AlertDialog.Builder((RelationActivity)getContext()); builder.setMessage("No relations found."); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { ((RelationActivity)getContext()).finish(); } }); builder.create(); builder.show(); 

This is the result: http://www.ozze.com.br/1.png

But, if I try to establish a theme, like this:

 AlertDialog.Builder builder = new AlertDialog.Builder(((RelationActivity)getContext()), android.R.style.Theme_Holo_Light_Dialog); 

This is the result: http://www.ozze.com.br/2.png

Please help me with this problem? When using a theme, the theme appears to surround the warning dialog.

+6
source share
2 answers

To set a different theme for the warning dialog, for example Theme.Holo.Light, try using ContextThemeWrapper, as used in Dialog.java in the android source:

 builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog)) 
+5
source

Here is the link of the Original answer here

For quick reference, I post here
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 ); 
+5
source

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


All Articles