Skip to content

Instantly share code, notes, and snippets.

@ahndwon
Created September 23, 2020 12:16
Show Gist options
  • Save ahndwon/e08df7f3b78d4532141ce5537194ec13 to your computer and use it in GitHub Desktop.
Save ahndwon/e08df7f3b78d4532141ce5537194ec13 to your computer and use it in GitHub Desktop.
TextViewBindingAdapter
@BindingAdapter("textResId")
fun TextView.setStringResId(@StringRes value: Int) {
if (value == 0) return
setText(value)
}
@BindingAdapter("textColorResId")
fun TextView.setTextColorResId(@ColorRes value: Int) {
if (value == 0) return
setTextColor(ContextCompat.getColor(context, value))
}
@BindingAdapter("drawableStartResId")
fun TextView.setDrawableStartResId(@DrawableRes value: Int) {
if (value == 0) return
setCompoundDrawablesWithIntrinsicBounds(value, 0, 0, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment