0
我尝试使用三元运算符来更改按钮的文本颜色。 类似的东西:这里是xml。数据绑定设置颜色
<Button
android:id="@+id/actionButton"
android:layout_width="113dp"
android:layout_height="30dp"
android:background="@drawable/button"
android:backgroundTint="@{selected ? R.color.white : R.color.turquoise}"
android:text="@{selected ? "Selected " : "Select "}"
android:textColor="@{selected ? @color/white : @color/turquoise}"
android:onClick="@{(view) -> handler.selectClick(view)}"/>
但颜色设置不正确。我得到一些奇怪的紫色颜色。
我试图
<import type="com.myapp.R" />
android:textColor="@{selected ? R.color.white : R.color.turquoise}"
具有相同的结果。
我应该怎么做?
你绿松石色哟检查你设置正确的颜色代码? –
是的。颜色很好。 android:textColor =“@ color/turquoise”根据需要工作 – Shmuel