且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

找不到Android数据绑定属性

更新时间:2022-06-26 05:48:50

我认为我已经找到了解决方案.要激活数据绑定,您需要使用@{}表达式,并且括号中的内容必须是有效的Java代码.因此,文字字符串必须用引号引起来......必须在XML属性值内编码为".全部放在一起,您将得到:

I think I've hit upon the solution. To activate data binding, you need to use a @{} expression, and what's in the braces must be valid Java code. So a literal string must be enclosed in quotes... which must be encoded as " inside an XML attribute value. Put it all together and you get:

<include
    layout="@layout/custom_edit_text"
    app:hint123="@{&quot;Email&quot;}"/>

数据绑定确实适用于包含文件,只是文字的语法有些复杂.我遇到了同样的问题,该表格正在我的项目中运行.

Data binding does work for include files, it's just that the syntax for a literal is a bit convoluted. I had the same issue and this form is working in my project.