我有一个自定义属性,声明为字符串类型。当我在XML中以纯字符串形式传递值时(如
app:cpb_title="sometsring"
),它可以正常工作,但是当我尝试使用数据绑定(如 app:cpb_title"@{model.someStringField}"
)时,会出现错误"cannot find setter for "app:cpb_title" that accepts parameter type java.lang.String"。
我该如何解决这个问题?
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;