How can I change the background of Android alert dialogs?

Your approach won’t work. It seems AlertDialog (and Builder) hardcode the theme and don’t honor alertDialogStyle anywhere:

protected AlertDialog(Context context) {
    this(context, com.android.internal.R.style.Theme_Dialog_Alert);
}

public Builder(Context context) {
    this(context, com.android.internal.R.style.Theme_Dialog_Alert);
}

They came to the same conclusion here.

A custom dialog class derived from AlertDialog that calls the protected constructor AlertDialog(context, R.style.MyOpaqueAlertDialog) would be a workaround.

In the latest android source, there is a new public constructor for AlertDialog.Builder that takes a theme argument. Unfortunately, it hasn’t been released yet (maybe in Gingerbread?).

Leave a Comment