Created
September 23, 2020 12:16
-
-
Save ahndwon/e08df7f3b78d4532141ce5537194ec13 to your computer and use it in GitHub Desktop.
TextViewBindingAdapter
This file contains hidden or 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
@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