阅读量:0
- 设置ImageView的图片加载:
@BindingAdapter("imageUrl") fun loadImage(view: ImageView, url: String) { Glide.with(view.context).load(url).into(view) }
- 设置TextView的文本颜色:
@BindingAdapter("textColor") fun setTextColor(view: TextView, colorResId: Int) { view.setTextColor(ContextCompat.getColor(view.context, colorResId)) }
- 设置View的可见性:
@BindingAdapter("visibility") fun setVisibility(view: View, isVisible: Boolean) { view.visibility = if (isVisible) View.VISIBLE else View.GONE }
- 设置RecyclerView的数据列表:
@BindingAdapter("data") fun setData(recyclerView: RecyclerView, data: List<Any>) { (recyclerView.adapter as MyAdapter).setData(data) }
- 设置Button的点击事件:
@BindingAdapter("clickListener") fun setClickListener(button: Button, listener: View.OnClickListener) { button.setOnClickListener(listener) }