File tree Expand file tree Collapse file tree
extensionslib/src/main/java/com/omega_r/libs/extensions/context Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.omega_r.libs.extensions.context
22
33import android.content.Context
44import android.graphics.drawable.AnimatedVectorDrawable
5+ import android.graphics.drawable.ColorDrawable
56import android.graphics.drawable.Drawable
67import android.os.Build
78import android.util.TypedValue
@@ -17,9 +18,7 @@ fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? {
1718
1819@RequiresApi(Build .VERSION_CODES .LOLLIPOP )
1920fun Context.getAnimatedVectorDrawable (@DrawableRes res : Int ): AnimatedVectorDrawable ? {
20- val drawable = getCompatDrawable(res)
21- if (drawable == null || drawable !is AnimatedVectorDrawable ) return null
22- return drawable
21+ return getCompatDrawable(res) as ? AnimatedVectorDrawable
2322}
2423
2524fun Context.getCompatColor (@ColorRes id : Int ): Int {
@@ -30,4 +29,8 @@ fun Context.getColorByAttribute(@AttrRes attrInt: Int): Int {
3029 return TypedValue ().run {
3130 if (theme.resolveAttribute(attrInt, this , true )) data else 0
3231 }
32+ }
33+
34+ fun Context.getColorDrawableByAttribute (@AttrRes attrInt : Int ): ColorDrawable {
35+ return ColorDrawable (getColorByAttribute(attrInt))
3336}
You can’t perform that action at this time.
0 commit comments