Reputation: 180
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.
Upvotes: 7
Views: 17804
Reputation: 10586
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 );
Upvotes: 9
Reputation: 11191
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))
Upvotes: 10