Created
April 30, 2018 05:10
-
-
Save jbarr21/3e6f518b212d341c03fbcbb25a2caa82 to your computer and use it in GitHub Desktop.
This file contains 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
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