Android 色调不起作用<;数据绑定中的21版本
我正在使用基于布尔标志的Android 色调不起作用<;数据绑定中的21版本,android,android-databinding,Android,Android Databinding,我正在使用基于布尔标志的ImageView的tint矢量可绘制。此代码适用于>=21版本。但在中仍有失败。甚至完全按照要求使用该方法: @BindingMethods({ @BindingMethod( type = "androidx.appcompat.widget.AppCompatImageView", attribute = "android:tint", method = "setImageTintList" ) })
ImageView
的tint
矢量可绘制。此代码适用于>=21版本。但在中仍有失败。甚至完全按照要求使用该方法:
@BindingMethods({
@BindingMethod(
type = "androidx.appcompat.widget.AppCompatImageView",
attribute = "android:tint",
method = "setImageTintList"
)
})
这个BindingAdapter将以编程方式设置色调…它对我很有用
@BindingAdapter("android:tint")
fun AppCompatImageView.setImageTint(@ColorInt color: Int) {
setColorFilter(color)
}
用法
testcaseapp:tint
Yes我已经试过了,它导致了一个错误<代码>:在androidx.appcompat.widget.AppCompatImageView上找不到参数类型为int的属性“app:tint”的setter。您尝试过吗
@Mykhailo不,我已经迁移到AndroidX
,我相信AndroidX
和支持的类之间没有区别。因为AndroidX只是一个重命名过程。这回答了你的问题吗?马丁:是的,我今天就是这么做的。我创建了BindingAdapter,并以编程方式设置了tint,这在所有版本上都可以使用。Android绑定库没有为@Khemraj添加方法。您可以提出一个问题:>>有一个问题,请注意解释您的代码是什么?这是一个BindingAdapter,它将以编程方式设置tint…它对我有效
@BindingMethods({
@BindingMethod(
type = "androidx.appcompat.widget.AppCompatImageView",
attribute = "android:tint",
method = "setImageTintList"
)
})
@BindingAdapter("android:tint")
fun AppCompatImageView.setImageTint(@ColorInt color: Int) {
setColorFilter(color)
}
<androidx.appcompat.widget.AppCompatImageView
android:tint="@color/primary"
...
/>