Created
February 18, 2022 16:28
-
-
Save L-Briand/a6a78d69f739ac29c1d2ba6cd8de3aed to your computer and use it in GitHub Desktop.
Android: Resolve drawable theme attribute from context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T> TypedArray.autoRecycle(block: TypedArray.() -> T): T { | |
val result = block() | |
recycle() | |
return result | |
} | |
fun resolveDrawable(context: Context, @AttrRes attr: Int): Drawable? = | |
context.theme.obtainStyledAttributes(intArrayOf(attr)).autoRecycle { getDrawable(0) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment