Skip to content

Commit e429c5e

Browse files
Martin NordholtsJean-Baptiste Queru
authored andcommitted
Support custom themes with AlertDialog.Builder
Add a constructor to AlertDialog.Builder with a 'theme' parameter so that e.g. the buttons in a dialog built with AlertDialog.Builder can be themed. Change-Id: Ie1b1c9706ad2146c8b64dd91fe249c6855c6ac65
1 parent e82ff9e commit e429c5e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

api/current.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19067,6 +19067,18 @@
1906719067
<parameter name="context" type="android.content.Context">
1906819068
</parameter>
1906919069
</constructor>
19070+
<constructor name="AlertDialog.Builder"
19071+
type="android.app.AlertDialog.Builder"
19072+
static="false"
19073+
final="false"
19074+
deprecated="not deprecated"
19075+
visibility="public"
19076+
>
19077+
<parameter name="context" type="android.content.Context">
19078+
</parameter>
19079+
<parameter name="theme" type="int">
19080+
</parameter>
19081+
</constructor>
1907019082
<method name="create"
1907119083
return="android.app.AlertDialog"
1907219084
abstract="false"

core/java/android/app/AlertDialog.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,22 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
265265

266266
public static class Builder {
267267
private final AlertController.AlertParams P;
268+
private int mTheme;
268269

269270
/**
270271
* Constructor using a context for this builder and the {@link AlertDialog} it creates.
271272
*/
272273
public Builder(Context context) {
274+
this(context, com.android.internal.R.style.Theme_Dialog_Alert);
275+
}
276+
277+
/**
278+
* Constructor using a context and theme for this builder and
279+
* the {@link AlertDialog} it creates.
280+
*/
281+
public Builder(Context context, int theme) {
273282
P = new AlertController.AlertParams(context);
283+
mTheme = theme;
274284
}
275285

276286
/**
@@ -783,7 +793,7 @@ public Builder setRecycleOnMeasureEnabled(boolean enabled) {
783793
* to do and want this to be created and displayed.
784794
*/
785795
public AlertDialog create() {
786-
final AlertDialog dialog = new AlertDialog(P.mContext);
796+
final AlertDialog dialog = new AlertDialog(P.mContext, mTheme);
787797
P.apply(dialog.mAlert);
788798
dialog.setCancelable(P.mCancelable);
789799
dialog.setOnCancelListener(P.mOnCancelListener);

0 commit comments

Comments
 (0)