【发布时间】:2017-09-30 20:04:27
【问题描述】:
是否可以使用 android 的数据绑定从 xml 中引用颜色?
这很好用:
android:textColor="@{inputValue == null ? 0xFFFBC02D : 0xFFFFEB3B}"
但事实并非如此:
android:textColor="@{inputValue == null ? @color/red : @color/blue}"
在这里举报:https://issuetracker.google.com/issues/38021292
* 编辑 *
事实证明,只有在极端情况下才会出现 id 问题/错误。我的xml:
<TextView
android:id="@+id/input_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{inputValue}"
android:textColor="@{showAsEmpty ? @color/registerInputEmpty : @color/registerInputSet}"
tools:text="Select to edit"/>
问题在于 inputValue 参数和 input_value id。它们成为数据绑定中的相同 inputValue 字段。如果您设置自定义颜色,这只是一个问题。来自 Google 的错误,应该会在下次更新中修复。
【问题讨论】:
-
出了点问题。我猜你还没有定义
red或blue颜色资源。它应该与android:textColor="@color/red"或android:textColor="@color/blue"一起使用,所以请检查一下。最后,错误是什么。
标签: android data-binding colors resources android-databinding