ChaosLeung / PinView

A PIN view library for Android. Use to enter PIN/OTP/password etc.
Apache License 2.0
627 stars 119 forks source link

DataBinding doesn't work with drawables #44

Closed vlytvyne closed 4 years ago

vlytvyne commented 5 years ago

I'm trying to do something like this: app:lineColor="@{viewmodel.isError ? @drawable/selector_pin_view_error : @drawable/selector_pin_view}" but there is no setter for attribute "app:lineColor" with parameter type Drawable. Worth mentioning that databinding does work with colors, like this: app:lineColor="@{viewmodel.isError ? @color/error : @color/default}"

vlytvyne commented 5 years ago

The easiest workaround I found is to create my own BindingAdapter: @BindingAdapter("lineColor") fun PinView.setLineColor(@ColorRes id: Int) { this.setLineColor( ResourcesCompat.getColorStateList(resources, id, null)) } Then you can use data binding as follows: app:lineColor="@{viewmodel.isError ? R.color.error : R.color.selector_pin_view }"