Skip to content

Instantly share code, notes, and snippets.

@jbarr21
Created April 30, 2018 05:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarr21/3e6f518b212d341c03fbcbb25a2caa82 to your computer and use it in GitHub Desktop.
Save jbarr21/3e6f518b212d341c03fbcbb25a2caa82 to your computer and use it in GitHub Desktop.
class VectorDrawableInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): InflateResult {
val result = chain.proceed(chain.request())
(result.view() as? TextView)?.let { textView ->
result.context().obtainStyledAttributes(result.attrs(), intArrayOf(android.R.attr.drawableLeft))?.let { ta ->
val drawableRes = ta.getResourceId(0, 0)
if (drawableRes != 0) {
val drawable = AppCompatResources.getDrawable(result.context(), drawableRes)
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
}
ta.recycle()
}
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment