Browse Source

Respect md_color_button_text attribute for action button text color, resolves #1750

Aidan Follestad 6 years ago
parent
commit
ef0431c647

+ 3 - 1
core/src/main/java/com/afollestad/materialdialogs/internal/button/DialogActionButton.kt

@@ -69,7 +69,9 @@ class DialogActionButton(
 
     // Text color
     val theme = inferTheme(appContext)
-    enabledColor = resolveColor(appContext, attr = R.attr.colorPrimary)
+    enabledColor = resolveColor(appContext, attr = R.attr.md_color_button_text) {
+      resolveColor(appContext, attr = R.attr.colorPrimary)
+    }
     val disabledColorRes =
       if (theme == LIGHT) R.color.md_disabled_text_light_theme
       else R.color.md_disabled_text_dark_theme

+ 7 - 2
core/src/main/java/com/afollestad/materialdialogs/utils/MDUtil.kt

@@ -96,12 +96,17 @@ object MDUtil {
   fun resolveColor(
     context: Context,
     @ColorRes res: Int? = null,
-    @AttrRes attr: Int? = null
+    @AttrRes attr: Int? = null,
+    fallback: (() -> Int)? = null
   ): Int {
     if (attr != null) {
       val a = context.theme.obtainStyledAttributes(intArrayOf(attr))
       try {
-        return a.getColor(0, 0)
+        val result = a.getColor(0, 0)
+        if (result == 0 && fallback != null) {
+          return fallback()
+        }
+        return result
       } finally {
         a.recycle()
       }