Last active
August 27, 2018 15:42
-
-
Save SeongUgJung/5b16732dec26273ab41e46691b6abc70 to your computer and use it in GitHub Desktop.
drawable from resource
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
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
> | |
<data> | |
<variable | |
name="vm" | |
type="MainViewModel" | |
/> | |
</data> | |
<TextView | |
android:layout_width="50dp" | |
android:layout_height="50dp" | |
android:drawableLeft="@{vm.textLeftImage}" | |
/> | |
</layout> |
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
class MainViewModel { | |
val textLeftImage = ObservableInt(R.drawable.search) | |
} |
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("android:drawableLeft") | |
fun bindingVectorDrawableLeft(textView: TextView, resourceId: Int) { | |
val drawable = AppCompatResources.getDrawable(textView.context, resourceId) | |
val drawables = textView.compoundDrawables | |
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, | |
drawables[1], drawables[2], drawables[3]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment