Browse Source

Fix rounded corners for custom background color

plusCubed 10 years ago
parent
commit
50196a95ed

+ 7 - 2
library/src/main/java/com/afollestad/materialdialogs/DialogInit.java

@@ -4,6 +4,7 @@ import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
 import android.os.Build;
 import android.os.Build;
 import android.text.InputType;
 import android.text.InputType;
 import android.text.method.LinkMovementMethod;
 import android.text.method.LinkMovementMethod;
@@ -63,8 +64,12 @@ class DialogInit {
         dialog.setCancelable(builder.cancelable);
         dialog.setCancelable(builder.cancelable);
         if (builder.backgroundColor == 0)
         if (builder.backgroundColor == 0)
             builder.backgroundColor = DialogUtils.resolveColor(builder.context, R.attr.md_background_color);
             builder.backgroundColor = DialogUtils.resolveColor(builder.context, R.attr.md_background_color);
-        if (builder.backgroundColor != 0)
-            dialog.view.setBackgroundColor(builder.backgroundColor);
+        if (builder.backgroundColor != 0) {
+            GradientDrawable drawable = new GradientDrawable();
+            drawable.setCornerRadius(builder.context.getResources().getDimension(R.dimen.md_bg_corner_radius));
+            drawable.setColor(builder.backgroundColor);
+            DialogUtils.setBackgroundCompat(dialog.view, drawable);
+        }
 
 
         // Retrieve action button colors from theme attributes or the Builder
         // Retrieve action button colors from theme attributes or the Builder
         builder.positiveColor = DialogUtils.resolveColor(builder.context, R.attr.md_positive_color, builder.positiveColor);
         builder.positiveColor = DialogUtils.resolveColor(builder.context, R.attr.md_positive_color, builder.positiveColor);

+ 2 - 0
library/src/main/res/values/dimens.xml

@@ -71,4 +71,6 @@
     <dimen name="md_simplelist_icon">40dp</dimen>
     <dimen name="md_simplelist_icon">40dp</dimen>
     <dimen name="md_simplelist_icon_margin">16dp</dimen>
     <dimen name="md_simplelist_icon_margin">16dp</dimen>
 
 
+    <dimen name="md_bg_corner_radius">2dp</dimen>
+
 </resources>
 </resources>