Jelajahi Sumber

Using color settings in the Builder will override global theme attributes for just that dialog. Resolves #566.

Aidan Follestad 10 tahun lalu
induk
melakukan
375e0dfad4

+ 12 - 6
library/src/main/java/com/afollestad/materialdialogs/DialogInit.java

@@ -74,10 +74,14 @@ class DialogInit {
         }
 
         // Retrieve action button colors from theme attributes or the Builder
-        builder.positiveColor = DialogUtils.resolveColor(builder.context, R.attr.md_positive_color, builder.positiveColor);
-        builder.neutralColor = DialogUtils.resolveColor(builder.context, R.attr.md_neutral_color, builder.neutralColor);
-        builder.negativeColor = DialogUtils.resolveColor(builder.context, R.attr.md_negative_color, builder.negativeColor);
-        builder.widgetColor = DialogUtils.resolveColor(builder.context, R.attr.md_widget_color, builder.widgetColor);
+        if (!builder.positiveColorSet)
+            builder.positiveColor = DialogUtils.resolveColor(builder.context, R.attr.md_positive_color, builder.positiveColor);
+        if (!builder.neutralColorSet)
+            builder.neutralColor = DialogUtils.resolveColor(builder.context, R.attr.md_neutral_color, builder.neutralColor);
+        if (!builder.negativeColorSet)
+            builder.negativeColor = DialogUtils.resolveColor(builder.context, R.attr.md_negative_color, builder.negativeColor);
+        if (!builder.widgetColorSet)
+            builder.widgetColor = DialogUtils.resolveColor(builder.context, R.attr.md_widget_color, builder.widgetColor);
 
         // Retrieve default title/content colors
         if (!builder.titleColorSet) {
@@ -156,8 +160,10 @@ class DialogInit {
         }
 
         // Setup divider color in case content scrolls
-        final int dividerFallback = DialogUtils.resolveColor(dialog.getContext(), R.attr.md_divider);
-        builder.dividerColor = DialogUtils.resolveColor(builder.context, R.attr.md_divider_color, dividerFallback);
+        if (!builder.dividerColorSet) {
+            final int dividerFallback = DialogUtils.resolveColor(dialog.getContext(), R.attr.md_divider);
+            builder.dividerColor = DialogUtils.resolveColor(builder.context, R.attr.md_divider_color, dividerFallback);
+        }
         dialog.view.setDividerColor(builder.dividerColor);
 
         // Setup title and title frame

+ 10 - 0
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -415,6 +415,11 @@ public class MaterialDialog extends DialogBase implements
         protected boolean titleColorSet = false;
         protected boolean contentColorSet = false;
         protected boolean itemColorSet = false;
+        protected boolean positiveColorSet = false;
+        protected boolean neutralColorSet = false;
+        protected boolean negativeColorSet = false;
+        protected boolean widgetColorSet = false;
+        protected boolean dividerColorSet = false;
 
         @DrawableRes
         protected int listSelector;
@@ -770,6 +775,7 @@ public class MaterialDialog extends DialogBase implements
 
         public Builder positiveColor(@ColorInt int color) {
             this.positiveColor = color;
+            this.positiveColorSet = true;
             return this;
         }
 
@@ -792,6 +798,7 @@ public class MaterialDialog extends DialogBase implements
 
         public Builder negativeColor(@ColorInt int color) {
             this.negativeColor = color;
+            this.negativeColorSet = true;
             return this;
         }
 
@@ -814,6 +821,7 @@ public class MaterialDialog extends DialogBase implements
 
         public Builder neutralColor(@ColorInt int color) {
             this.neutralColor = color;
+            this.neutralColorSet = true;
             return this;
         }
 
@@ -923,6 +931,7 @@ public class MaterialDialog extends DialogBase implements
 
         public Builder widgetColor(@ColorInt int color) {
             this.widgetColor = color;
+            this.widgetColorSet = true;
             return this;
         }
 
@@ -936,6 +945,7 @@ public class MaterialDialog extends DialogBase implements
 
         public Builder dividerColor(@ColorInt int color) {
             this.dividerColor = color;
+            this.dividerColorSet = true;
             return this;
         }