File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
library/src/main/java/com/minibugdev/drawablebadge Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import android.support.annotation.ColorRes
99import android.support.annotation.DimenRes
1010import android.support.annotation.DrawableRes
1111import android.support.v4.content.ContextCompat
12+ import android.support.v4.content.res.ResourcesCompat
1213import android.text.TextPaint
1314
1415class DrawableBadge private constructor(val context : Context ,
@@ -34,7 +35,17 @@ class DrawableBadge private constructor(val context: Context,
3435 private var isShowBorder: Boolean? = null
3536 private var maximumCounter: Int? = null
3637
37- fun drawableResId (@DrawableRes drawableRes : Int ) = apply { this .bitmap = BitmapFactory .decodeResource(context.resources, drawableRes) }
38+ fun drawableResId (@DrawableRes drawableRes : Int ) = apply {
39+ val res = context.resources
40+ bitmap = BitmapFactory .decodeResource(res, drawableRes)
41+
42+ if (bitmap == null ) {
43+ val d = ResourcesCompat .getDrawable(res, drawableRes, null )?.current
44+ if (d is BitmapDrawable ) {
45+ bitmap = d.bitmap
46+ }
47+ }
48+ }
3849
3950 fun drawable (drawable : Drawable ) = apply {
4051 if (drawable is BitmapDrawable ) {
You can’t perform that action at this time.
0 commit comments