【发布时间】:2020-07-14 11:53:37
【问题描述】:
我有自定义属性,它被声明为字符串类型,当像这样 app:cpb_title="sometsring" 将值作为 xml 中的字符串传递时,它可以工作,但是当我尝试像这样 app:cpb_title"@{model.someStringField}" 这样的数据绑定时,它给了我错误 “找不到接受参数类型 java.lang.String 的“app:cpb_title”的设置器”
我该如何解决?
attrs.xml
<declare-styleable name="CircularProgressBar">
<attr name="cpb_hasShadow" format="boolean"/>
<attr name="cpb_progressColor" format="string"/>
<attr name="cpb_backgroundColor" format="string"/>
<attr name="cpb_title" format="string"/>
<attr name="cpb_titleColor" format="string"/>
<attr name="cpb_subtitle" format="string"/>
<attr name="cpb_subtitleColor" format="string"/>
<attr name="cpb_strokeWidth" format="integer"/>
</declare-styleable>
内部视图类
String t = a.getString(R.styleable.CircularProgressBar_cpb_title);
if(t!=null)
mTitle = t;
【问题讨论】:
标签: android data-binding android-custom-attributes