public class SpaceBean extends BaSEObservable { private String selectedthemecolor; @Nullable @Bindable public String getSelectedthemecolor() { return selectedthemecolor; } public voID setSelectedthemecolor(String selectedthemecolor) { this.selectedthemecolor = selectedthemecolor; notifyPropertyChanged(BR.selectedthemecolor); }}
我想在线性布局androID:background属性中使用数据绑定表达式,如:
<linearLayout androID:ID="@+ID/ll_space_detail_overlay" androID:layout_wIDth="match_parent" androID:layout_height="144dp" androID:layout_alignParentBottom="true" androID:layout_marginBottom="@dimen/common_margin" androID:layout_marginEnd="@dimen/common_margin" androID:layout_marginStart="@dimen/common_margin" androID:background="@{bean.selectedthemecolor}" androID:clickable="true" androID:orIEntation="vertical" androID:padding="@dimen/common_padding" androID:visibility="visible">
但它无法编译错误:
解决方法 因为没有像VIEw.setBackground(“#f0f”)这样的方法!Error:(80,35) Cannot find the setter for attribute
‘androID:background’ with parameter type java.lang.String on
androID.Widget.linearLayout.
相反,您可以在SpaceBean.getSelectedthemecolor()中返回Drawable或ARGB颜色值.
例如:
public class SpaceBean extends BaSEObservable { private String selectedthemecolor; @Nullable @Bindable public Drawable getSelectedthemecolor() { return new colorDrawable(color.parsecolor(selectedthemecolor)); } public voID setSelectedthemecolor(String selectedthemecolor) { this.selectedthemecolor = selectedthemecolor; notifyPropertyChanged(BR.selectedthemecolor); }}总结
以上是内存溢出为你收集整理的android上的android数据绑定:使用字符串颜色代码的background属性全部内容,希望文章能够帮你解决android上的android数据绑定:使用字符串颜色代码的background属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)