Proper way to setup attr colors

This commit is contained in:
topjohnwu
2020-09-16 22:16:28 -07:00
parent 8c19654d20
commit 9e5cb6cb91
5 changed files with 33 additions and 31 deletions
@@ -297,3 +297,17 @@ fun CardView.setCardBackgroundColorAttr(attr: Int) {
fun ImageView.setTint(color: Int) {
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(color))
}
@BindingAdapter("tintAttr")
fun ImageView.setTintAttr(attr: Int) {
val tv = TypedValue()
context.theme.resolveAttribute(attr, tv, true)
ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(tv.data))
}
@BindingAdapter("textColorAttr")
fun TextView.setTextColorAttr(attr: Int) {
val tv = TypedValue()
context.theme.resolveAttribute(attr, tv, true)
setTextColor(tv.data)
}