[英]Problem with ternary conditional in xml with data-binding
I have the 2 following situation around this button with some params being set by data-binding and I've found that the problem is about a ternary operation with the true and false results order.我在这个按钮周围有以下两种情况,其中一些参数是通过数据绑定设置的,我发现问题是关于具有真假结果顺序的三元运算。
<Button
android:id="@+id/tbIbArrowBack"
android:layout_width="@dimen/extra_large_size_32"
android:layout_height="@dimen/extra_large_size_32"
android:layout_marginStart="@dimen/activity_default_medium_margin"
android:background="@drawable/ic_arrow_back_white_24dp"
android:onClick="@{() -> manager.onClick()}"
android:visibility="@{manager.showBackButton ? View.VISIBLE : View.GONE, default=gone}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
android:background="@{manager.backButtonColor == 0? manager.backButtonColor: @drawable/ic_arrow_back_white_24dp,default=@drawable/ic_arrow_back_white_24dp}
android:background="@{manager.backButtonColor == 0? manager.backButtonColor: @drawable/ic_arrow_back_white_24dp,default=@drawable/ic_arrow_back_white_24dp}
android:background="@{manager.backButtonColor?= 0: @drawable/ic_arrow_back_white_24dp. manager,backButtonColor, default=@drawable/ic_arrow_back_white_24dp}"
android:background="@{manager.backButtonColor?= 0: @drawable/ic_arrow_back_white_24dp. manager,backButtonColor, default=@drawable/ic_arrow_back_white_24dp}"
the item 1 and 2 are how I tried to do a customizable background.第 1 项和第 2 项是我尝试制作可自定义背景的方式。 While
@drawable/ic_arrow_back_white_24dp
is in second position of ternary operation it won't work, but while it is in first position of ternary operation it work.虽然
@drawable/ic_arrow_back_white_24dp
在三元运算的第二个 position 中它不起作用,但是当它在三元运算的第一个 position 中时它起作用。 Can someone explain to me why 1 won't compile?有人可以向我解释为什么 1 不会编译吗?
What is the data type of "manager.backButtonColor"? “manager.backButtonColor”的数据类型是什么? I think you are using 2 different data type for the binding.
我认为您正在使用 2 种不同的数据类型进行绑定。
Could you just try out like this你能像这样试试吗
@{data.isSelectMessage ? @drawable/ic_menu_message_selected : @drawable/ic_menu_message_deselected}
because it perfectly works for me and I used it like this.因为它非常适合我,我就这样使用它。
<ImageView
android:id="@+id/img_menu_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:alpha="@{alpha}"
android:background="@color/white"
android:src="@{data.isSelectMessage ? @drawable/ic_menu_message_selected : @drawable/ic_menu_message_deselected}"
tools:src="@drawable/ic_menu_message_selected" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.