出现错误“与属性色调(attr)颜色不兼容”。在使用数据绑定时

时间:2019-01-23 07:29:31

标签: android android-databinding

我正在尝试在运行时使用数据绑定在图像上设置色彩

    <ImageView
        android:id="@+id/txtAppointmentEnable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src='@{paymentMethod.getActiveStatus().equalsIgnoreCase("DISABLE") ?  @drawable/ic_action_navigation_close : @drawable/ic_add_white_36dp}'
        android:tint='@{paymentMethod.getActiveStatus().equalsIgnoreCase("DISABLE") ?  @color/favourite_red : @color/green_light'/>

我遇到错误

 error: '@{paymentMethod.getActiveStatus().equalsIgnoreCase("DISABLE") ?  @color/favourite_red : @color/green_light' is incompatible with attribute tint (attr) color.

此问题的可能解决方法是什么。

1 个答案:

答案 0 :(得分:0)

数据绑定不允许双引号。使用反引号(`)代替“。最后我也添加了}。

<ImageView
        android:id="@+id/txtAppointmentEnable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src='@{paymentMethod.getActiveStatus().equalsIgnoreCase(`DISABLE`) ?  @drawable/ic_action_navigation_close : @drawable/ic_add_white_36dp}'
        android:tint='@{paymentMethod.getActiveStatus().equalsIgnoreCase(`DISABLE`) ?  @color/favourite_red : @color/green_light'}/>