android-ktx icon indicating copy to clipboard operation
android-ktx copied to clipboard

Resources.Theme.resolveAttribute extension

Open romtsn opened this issue 7 years ago • 0 comments

To facilitate the retrieving of an attribute from a theme, I'd like to propose the following extension:

inline fun Resources.Theme.resolveAttribute(
    resId: Int,
    resolveRefs: Boolean = true
): TypedValue = TypedValue().apply { resolveAttribute(resId, this, resolveRefs) }

So this will lead to the following change:

// before
val backgroundValue = TypedValue() 
context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true)

// after
val backgroundValue = context.theme.resolveAttribute(android.R.attr.selectableItemBackground)

romtsn avatar Jun 24 '18 10:06 romtsn