找不到接受参数类型 'androidx.databinding.ObservableField<java.lang.Boolean>' 的 <ProgressBar android:visibility> 的 getter

Cannot find a getter for <ProgressBar android:visibility> that accepts parameter type 'androidx.databinding.ObservableField<java.lang.Boolean>'

其他问题已通过将 kotlin-kapt 插件添加到 gradle 文件来解决,但我的问题似乎并没有因此而消失。我正在尝试设置进度条的可见性,以便用户知道应用程序何时在后台运行。我为此使用数据绑定,但出现编译错误:

找不到接受参数类型 'androidx.databinding.ObservableField<java.lang.Boolean>'

的 getter

我认为字符串或整数值都不能在那里工作。至少对于布尔方法,它不会抱怨 setter,只有 getter。尽管我将数据绑定与其他视图一起使用,但效果很好。 这就是我目前在 HomeViewModel 中实现我的解决方案的方式:

 @Bindable
    var barProgress = ObservableField<Boolean>()
    fun doSomething(){
        this.barProgress.set(true)
    }

    @BindingAdapter("android:visibility")
    fun setVisibility(view: View, visible: Boolean) {
        view.visibility = if (visible) View.INVISIBLE else View.VISIBLE
    }

在布局文件中:

<ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="15dp"
            android:layout_marginLeft="15dp"
            app:layout_constraintStart_toEndOf="@+id/tag_button"
            app:layout_constraintTop_toBottomOf="@+id/editTextTextMultiLine"
            android:visibility="@={myViewModel.barProgress}" //--> this is where it complains />

所以在我的 HomeViewModel 中,我应该能够将 barProgress 设置为 true 或 false。

我的build.gradle:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

知道我应该怎么做吗?

它只是清理和重建项目,我也不知道它是否相关但我替换了:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
}

与:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

不确定这是否也有助于解决问题。