我试图复制这个答案:设置包含布局的子元素的属性
我有一个简单的自定义\u edit\u text.xml
:
<;?xml version=“1.0”encoding=“utf-8”?>;
<;布局
xmlns:android=”http://schemas.android.com/apk/res/android“>;
<;数据>;
<;变量名称=“hint123”type=“String”/>;
</数据>;
<;android.support.design.widget.TextInputLayout
android:id=“@+id/emailInputLayout”
android:layout\u width=“包装内容”
android:layout_height=“wrap_content”>;
<;android.support.v7.widget.AppCompatiEditText
android:id=“@+id/emailField”
android:layout_width=“275dp”
android:layout\u height=“包装内容”
android:paddingBottom=“16dp”
android:paddingTop=“14dp”
android:hint=“@{hint123}”
android:textCursorDrawable=“@null”
android:background=“@drawable/edit_text_background”
android:fontFamily=“@font/eina_常规”
android:textColor=“@color/edit\u text\u color”
android:textColorHint=“@color/edit\u text\u color”
android:textSize=“15sp”
/&燃气轮机;
</android.support.design.widget.TextInputLayout>;
</布局>;
我将其包含在另一个文件中:
<;?xml version=“1.0”encoding=“utf-8”?>;
<;布局
xmlns:android=”http://schemas.android.com/apk/res/android"
xmlns:app=”http://schemas.android.com/apk/res-auto“>;
<;包括
layout=“@layout/custom\u edit\u text”
app:hint123=“电子邮件”/>;
</布局>;
然而,该项目拒绝编译后,一个干净的&;重新生成时出错:
AAPT:error:未找到属性hint123(aka inc.company.appname:hint123)。
有什么想法吗
我也有
数据绑定{
启用=真
}
在应用程序级别build.gradle中启用
我想我找到了解决办法。要激活数据绑定,需要使用@{}
表达式,大括号中的内容必须是有效的Java代码。所以文字字符串必须用引号括起来。。。必须将其编码为&;引用在XML属性值中。把这些放在一起,你会得到:
<;包括
layout=“@layout/custom\u edit\u text”
app:hint123=“@{quot;Email}”/>;
数据绑定对include文件有效,只是文字的语法有点复杂。我有同样的问题,这个表格正在我的项目中工作