Răsfoiți Sursa

Release 0.3.1

Aidan Follestad 10 ani în urmă
părinte
comite
d655cf60b2

+ 19 - 0
README.md

@@ -6,6 +6,10 @@ The code you see below is also found in the sample project. You can download a A
 
 ### What's New
 
+###### Version 0.3.1
+
+> 1. Global theming! A single attribute can be added to your Activity theme to make all dialogs dark. See the Theming section below.
+
 ###### Version 0.3.0
 
 > 1. `MaterialDialogCompat` allows easy migration from use of `AlertDialog` (see below).
@@ -328,6 +332,21 @@ To see more colors that fit the Material design palette, see this page: http://w
 
 ---
 
+### Global Theming
+
+If you don't want to manually make calls to `theme()` everytime you construct a dialog, you can put a single attribute in
+your Activity themes that makes all dialogs dark.
+
+``xml
+<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
+
+    <item name="md_dark_theme">true</item>
+
+</style>
+```
+
+---
+
 ### Misc
 
 If you need to access a View in the custom view set to a MaterialDialog, you can use `getCustomView()` of

+ 12 - 1
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -72,8 +72,19 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener,
     private ItemProcessor mItemProcessor;
     private boolean autoDismiss;
 
+    protected static ContextThemeWrapper getTheme(Builder builder) {
+        TypedArray a = builder.context.getTheme().obtainStyledAttributes(new int[]{R.attr.md_dark_theme});
+        boolean darkTheme = builder.theme == Theme.DARK;
+        try {
+            darkTheme = a.getBoolean(0, false);
+        } finally {
+            a.recycle();
+        }
+        return new ContextThemeWrapper(builder.context, darkTheme ? R.style.MD_Dark : R.style.MD_Light);
+    }
+
     protected MaterialDialog(Builder builder) {
-        super(new ContextThemeWrapper(builder.context, builder.theme == Theme.LIGHT ? R.style.MD_Light : R.style.MD_Dark));
+        super(getTheme(builder));
 
         this.regularFont = builder.regularFont;
         if (this.regularFont == null)

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

@@ -3,5 +3,6 @@
 
     <attr name="md_selector" format="reference" />
     <attr name="md_divider" format="color" />
+    <attr name="md_dark_theme" format="boolean" />
 
 </resources>

BIN
sample/sample.apk