首页 > 解决方案 > 出现错误“与属性色调 (attr) 颜色不兼容”。在使用数据绑定时

问题描述

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

    <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.

这个问题的可能解决方案是什么。

标签: androidandroid-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}'/>

推荐阅读