第一步:
<include
android:id="@+id/agl_include_toolbar"
layout="@layout/layout_toolbar"
app: goodsListVM ="@{goodsListVM}" />
必须添加id,app:toolbarViewModel这个标签要和你定义的变量名一致(如果你只想使用include组件,不需要数据绑定就可以不设置这个字段)
第二步
include的布局也要data化,并且添加variable名称要和前面传过来的一致
<data>
<variable
name="goodsListVM"
type="xxxxxxxx.GoodsListViewModel" />
</data>
使用方法,binding.agl_include_toolbar.viewid
viewid就是你include布局里的组件id。