ソースを参照

Added two new global theming attributes for background color and divider color.

Aidan Follestad 10 年 前
コミット
c86e16c89c

+ 7 - 0
README.md

@@ -388,6 +388,13 @@ or operating system. This behavior can be overridden in your Activity themes:
     -->
     <item name="md_item_color">#9C27B0</item>
 
+    <!-- This overrides the default dark or light dialog background color. Note that if you use
+        a dark color here, you should set md_dark_theme to true so text and selectors look visible -->
+    <item name="md_background_color">#37474F</item>
+
+    <!-- This overrides the color used for the top and bottom dividers used when content is scrollable -->
+    <item name="md_divider_color">#E91E63</item>
+
 </style>
 ```
 

+ 43 - 11
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -54,7 +54,8 @@ import java.util.List;
 public class MaterialDialog extends DialogBase implements View.OnClickListener {
 
     @IntDef({START, CENTER, END})
-    public @interface GravityInt {}
+    public @interface GravityInt {
+    }
 
     public static final int START = 0;
     public static final int CENTER = 1;
@@ -103,6 +104,11 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         this.view = LayoutInflater.from(getContext()).inflate(R.layout.md_dialog, null);
         this.setCancelable(builder.cancelable);
 
+        if (mBuilder.backgroundColor == 0)
+            mBuilder.backgroundColor = DialogUtils.resolveColor(mBuilder.context, R.attr.md_background_color);
+        if (mBuilder.backgroundColor != 0)
+            this.view.setBackgroundColor(mBuilder.backgroundColor);
+
         final int mdAccentColor = DialogUtils.resolveColor(mBuilder.context, R.attr.md_accent_color);
         if (mdAccentColor != 0) {
             mBuilder.positiveColor = mdAccentColor;
@@ -399,10 +405,15 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         topVisible = topVisible && titleFrame.getVisibility() == View.VISIBLE;
         bottomVisible = bottomVisible && hasActionButtons();
 
+        if (mBuilder.dividerColor == 0)
+            mBuilder.dividerColor = DialogUtils.resolveColor(mBuilder.context, R.attr.md_divider_color);
+        if (mBuilder.dividerColor == 0)
+            mBuilder.dividerColor = DialogUtils.resolveColor(getContext(), R.attr.md_divider);
+
         View titleBarDivider = view.findViewById(R.id.titleBarDivider);
         if (topVisible) {
             titleBarDivider.setVisibility(View.VISIBLE);
-            titleBarDivider.setBackgroundColor(DialogUtils.resolveColor(getContext(), R.attr.md_divider));
+            titleBarDivider.setBackgroundColor(mBuilder.dividerColor);
         } else {
             titleBarDivider.setVisibility(View.GONE);
         }
@@ -410,7 +421,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         View buttonBarDivider = view.findViewById(R.id.buttonBarDivider);
         if (bottomVisible) {
             buttonBarDivider.setVisibility(View.VISIBLE);
-            buttonBarDivider.setBackgroundColor(DialogUtils.resolveColor(getContext(), R.attr.md_divider));
+            buttonBarDivider.setBackgroundColor(mBuilder.dividerColor);
             setVerticalMargins(view.findViewById(R.id.buttonStackedFrame), 0, 0);
             setVerticalMargins(view.findViewById(R.id.buttonDefaultFrame), 0, 0);
         } else {
@@ -763,8 +774,12 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
 
         protected Context context;
         protected CharSequence title;
-        protected @GravityInt int titleGravity = Gravity.START;
-        protected @GravityInt int contentGravity = Gravity.START;
+        protected
+        @GravityInt
+        int titleGravity = Gravity.START;
+        protected
+        @GravityInt
+        int contentGravity = Gravity.START;
         protected int titleColor = -1;
         protected int contentColor = -1;
         protected CharSequence content;
@@ -797,6 +812,8 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         protected OnShowListener showListener;
         protected boolean forceStacking;
         protected boolean wrapCustomViewInScroll;
+        protected int dividerColor;
+        protected int backgroundColor;
 
         public Builder(@NonNull Context context) {
             this.context = context;
@@ -988,8 +1005,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         }
 
         public Builder neutralText(@StringRes int neutralRes) {
-            neutralText(this.context.getString(neutralRes));
-            return this;
+            return neutralText(this.context.getString(neutralRes));
         }
 
         public Builder neutralText(CharSequence message) {
@@ -998,8 +1014,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         }
 
         public Builder negativeText(@StringRes int negativeRes) {
-            negativeText(this.context.getString(negativeRes));
-            return this;
+            return negativeText(this.context.getString(negativeRes));
         }
 
         public Builder negativeText(CharSequence message) {
@@ -1055,8 +1070,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         }
 
         public Builder neutralColorRes(@ColorRes int colorRes) {
-            neutralColor(this.context.getResources().getColor(colorRes));
-            return this;
+            return neutralColor(this.context.getResources().getColor(colorRes));
         }
 
         public Builder neutralColor(int color) {
@@ -1064,6 +1078,24 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
             return this;
         }
 
+        public Builder dividerColorRes(@ColorRes int colorRes) {
+            return dividerColor(this.context.getResources().getColor(colorRes));
+        }
+
+        public Builder dividerColor(int color) {
+            this.dividerColor = color;
+            return this;
+        }
+
+        public Builder backgroundColorRes(@ColorRes int colorRes) {
+            return backgroundColor(this.context.getResources().getColor(colorRes));
+        }
+
+        public Builder backgroundColor(int color) {
+            this.backgroundColor = color;
+            return this;
+        }
+
         public Builder callback(ButtonCallback callback) {
             this.callback = callback;
             return this;

+ 4 - 0
library/src/main/res/values/attrs.xml

@@ -1,15 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 
+    <!-- These top three attributes are not accessible to library users -->
     <attr name="md_selector" format="reference" />
     <attr name="md_btn_selector" format="reference" />
     <attr name="md_divider" format="color" />
 
+    <!-- Accessible global theming attributes -->
     <attr name="md_dark_theme" format="boolean" />
     <attr name="md_title_color" format="color" />
     <attr name="md_content_color" format="color" />
     <attr name="md_accent_color" format="color" />
     <attr name="md_item_color" format="color" />
     <attr name="md_icon" format="reference" />
+    <attr name="md_background_color" format="color" />
+    <attr name="md_divider_color" format="color" />
 
 </resources>

+ 2 - 1
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -8,7 +8,6 @@ import android.text.Html;
 import android.text.InputType;
 import android.text.TextWatcher;
 import android.text.method.PasswordTransformationMethod;
-import android.view.Gravity;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
@@ -412,6 +411,8 @@ public class MainActivity extends ActionBarActivity implements FolderSelectorDia
                 .titleGravity(MaterialDialog.CENTER)
                 .titleColorRes(R.color.material_red_400)
                 .contentColorRes(android.R.color.white)
+                .backgroundColorRes(R.color.material_blue_grey_800)
+                .dividerColorRes(R.color.material_pink_500)
                 .theme(Theme.DARK)
                 .show();
     }

+ 5 - 0
sample/src/main/res/values/styles.xml

@@ -5,6 +5,11 @@
         <item name="colorPrimary">@color/material_indigo_500</item>
         <item name="colorPrimaryDark">@color/material_indigo_600</item>
         <item name="colorAccent">@color/material_pink_500</item>
+
+        <!--<item name="md_divider_color">@color/material_pink_500</item>-->
+        <!--<item name="md_background_color">@color/material_blue_grey_800</item>-->
+        <!--<item name="md_dark_theme">true</item>-->
+
     </style>
 
 </resources>