I'm creating an AlertDialog. If 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 set 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, can anyone help me with this issue? It looks like when using a theme, the theme "surrounds" the alert dialog.
This method is deprecated.
AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .
Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.
Android Alert Dialog is built with the use of three fields: Title, Message area, and Action Button.
To set a different Theme for the alert dialog like Theme.Holo.Light try to use ContextThemeWrapper as used in Dialog.java in android source:
builder = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog))
Here is link of Original answer here
For quick reference I am posting 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 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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With