【问题标题】:DataBinding issue with android:progressBackgroundTintandroid:progressBackgroundTint 的数据绑定问题
【发布时间】: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


【解决方案1】:

settersetProgressBackgroundTintListColorList 对象作为参数而不是int。如果要使用int,可以定义BindingAdapter,创建ColorList并手动调用函数

【讨论】:

    猜你喜欢
    • 2011-01-17
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 2011-10-18
    相关资源
    最近更新 更多