Skip to content

Commit 1d4432d

Browse files
committed
Add fun getDrawableByAttr
1 parent 2c2cd74 commit 1d4432d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

extensionslib/src/main/java/com/omega_r/libs/extensions/context/ResourceExtensions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ inline fun Context.getColorByAttribute(@AttrRes attrInt: Int): Int {
3838
@Suppress("NOTHING_TO_INLINE")
3939
inline fun Context.getColorDrawableByAttribute(@AttrRes attrInt: Int): ColorDrawable {
4040
return ColorDrawable(getColorByAttribute(attrInt))
41+
}
42+
43+
@Suppress("NOTHING_TO_INLINE")
44+
inline fun Context.getDrawableByAttribute(@AttrRes attrInt: Int): Drawable? {
45+
return TypedValue().run {
46+
if (theme.resolveAttribute(attrInt, this, true)) getCompatDrawable(data) else null
47+
}
4148
}

0 commit comments

Comments
 (0)