Skip to content

Instantly share code, notes, and snippets.

@toe-lie
Last active August 14, 2020 14:02
Show Gist options
  • Save toe-lie/127c19262a6c51e4d011650e9f377de3 to your computer and use it in GitHub Desktop.
Save toe-lie/127c19262a6c51e4d011650e9f377de3 to your computer and use it in GitHub Desktop.
Vector Drawable related code to support devices below 5.0
// To read vector drawable from xml attribute
val drawableResId = arr.getResourceId(R.styleable.GreenWayCountTextView_icon, -1)
if (drawableResId != -1) {
AppCompatResources.getDrawable(getContext(), drawableResId)?.let { drawable ->
setIcon(drawable)
}
}
// set drawable tint
TextViewCompat.setCompoundDrawableTintList(this,
ColorStateList.valueOf(ContextCompat.getColor(context, R.color.app_inactive_icon)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment