【发布时间】:2020-06-15 08:49:59
【问题描述】:
我正在尝试将数据绑定与 ProgressBar 一起使用,但我遇到了一些错误。
我有2组进度条,当我如下使用时,它工作正常,
<ProgressBar
android:id="@+id/firstAudioProgressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:progress="50"
android:progressBackgroundTint="@color/colorPrimary"
android:progressTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
但是,一旦我开始使用数据绑定在运行时决定 android:progressBackgroundTint 颜色,就会出现编译时错误,请参阅下面的代码和错误,
代码
<ProgressBar
android:id="@+id/firstAudioProgressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:progress="50"
android:progressBackgroundTint="@{track1.isLongest() ? @color/colorPrimary : @color/colorPrimaryDark}"
android:progressTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
错误
Cannot find a setter for <android.widget.ProgressBar android:progressBackgroundTint> that accepts parameter type 'int'
If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.
请告诉我,我该怎么办。提前致谢。
【问题讨论】:
-
你在 build.gradle 中设置了 dataBinding 吗?
-
我不认为如果我不在 build.gradle 中设置数据绑定,我会得到我得到的错误。我仍然交叉检查了它,它就在那里。已经设置好了。
标签: android data-binding