OSDN Git Service

Support custom themes with AlertDialog.Builder
authorMartin Nordholts <martin.nordholts@sonyericsson.com>
Tue, 15 Jun 2010 14:17:24 +0000 (16:17 +0200)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 5 Aug 2011 08:05:34 +0000 (16:05 +0800)
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

api/current.xml
core/java/android/app/AlertDialog.java

index e10b357..761cfa3 100644 (file)
 <parameter name="context" type="android.content.Context">
 </parameter>
 </constructor>
+<constructor name="AlertDialog.Builder"
+ type="android.app.AlertDialog.Builder"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="context" type="android.content.Context">
+</parameter>
+<parameter name="theme" type="int">
+</parameter>
+</constructor>
 <method name="create"
  return="android.app.AlertDialog"
  abstract="false"
index b459320..9712b2b 100644 (file)
@@ -265,12 +265,22 @@ public class AlertDialog extends Dialog implements DialogInterface {
     
     public static class Builder {
         private final AlertController.AlertParams P;
+        private int mTheme;
         
         /**
          * Constructor using a context for this builder and the {@link AlertDialog} it creates.
          */
         public Builder(Context context) {
+            this(context, com.android.internal.R.style.Theme_Dialog_Alert);
+        }
+
+        /**
+         * Constructor using a context and theme for this builder and
+         * the {@link AlertDialog} it creates.
+         */
+        public Builder(Context context, int theme) {
             P = new AlertController.AlertParams(context);
+            mTheme = theme;
         }
         
         /**
@@ -783,7 +793,7 @@ public class AlertDialog extends Dialog implements DialogInterface {
          * to do and want this to be created and displayed.
          */
         public AlertDialog create() {
-            final AlertDialog dialog = new AlertDialog(P.mContext);
+            final AlertDialog dialog = new AlertDialog(P.mContext, mTheme);
             P.apply(dialog.mAlert);
             dialog.setCancelable(P.mCancelable);
             dialog.setOnCancelListener(P.mOnCancelListener);