【问题标题】:error: <value> is incompatible with attribute <package>:<attribute_name> (attr) reference [weak]错误:<value> 与属性 <package> 不兼容:<attribute_name> (attr) 参考 [弱]
【发布时间】:2018-05-24 17:46:00
【问题描述】:

我正在尝试集成 this 库。我遇到了“缺少属性”的问题,所以我将这些属性添加到我的项目中:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <declare-styleable name="app">
        <attr name="isDone" format="boolean"/>
        <attr name="isVisible" format="boolean"/>
    </declare-styleable>
</resources>

之后,当我清理项目并再次运行构建过程时,我遇到了这个问题:

error: '@{viewModel.hasStartDate}' is incompatible with attribute com.example:isVisible (attr) reference [weak].
Message{kind=ERROR, text=error: '@{viewModel.hasStartDate}' is incompatible with attribute com.example:isVisible (attr) reference [weak]., sources=[/home/local/<USER_NAME>/.gradle/caches/transforms-1/files-1.1/DateTimeRangePicker-v1.3.aar/524561517fca999eba7db795be3a768d/res/layout/date_time_range_picker.xml:52], original message=, tool name=Optional.of(AAPT)}

在某些地方,其中之一是使用数据绑定的库生成的布局文件中的这一行:

    app:isDone="@{viewModel.isCompletable}"

在该库生成的 Kotlin 代码中,它被声明为:

  val isCompletable = ObservableBoolean()

这个库在 Kotlin 中。 是什么原因造成的?

是 KAPT 吗? 是数据绑定吗?

【问题讨论】:

    标签: java android kotlin android-databinding kapt


    【解决方案1】:

    声明的属性必须是string 类型

        <attr name="isDone" format="string"/>
        <attr name="isVisible" format="string"/>
    

    【讨论】:

      【解决方案2】:

      Xml 布局

      <android.support.design.widget.TextInputLayout
            android:layout_width=”match_parent”
            android:layout_height=”wrap_content”
            app:error=”@{loginInfo.passwordError}”>
            <EditText
              android:id=”@+id/password”
              android:layout_width=”match_parent”
              android:layout_height=”wrap_content”
              android:enabled=”@{loginInfo.existingUser}”
              android:hint=”@string/password”
              android:inputType=”textPassword”
              app:binding=”@{loginInfo.password}”/>
          </android.support.design.widget.TextInputLayout>
      

      模型类

      public class LoginInfo {
        public BindableBoolean existingUser = new BindableBoolean();
      }
      

      BindableBoolean 类

      import org.parceler.Parcel;
      
      @Parcel
      public class BindableBoolean extends BaseObservable {
          boolean mValue;
      
          public boolean get() {
              return mValue;
          }
      
          public void set(boolean value) {
              if (mValue != value) {
                  this.mValue = value;
                  notifyChange();
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-06-15
        • 1970-01-01
        • 2018-06-20
        • 1970-01-01
        • 1970-01-01
        • 2020-08-31
        • 2018-06-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多