我想创建一个自定义 Android 视图(MyCustomView)。在这个视图中,我想要一个自定义类型(MyCustomType)的属性。与此类似:
MyCustomView extends LinearLayout {
private MyCustomType prop1;
public MyCustomType getProp1()
{
return this.prop1;
}
public void setProp1(MyCustomType value)
{
this.prop1 = value;}
}
}
到目前为止,一切都很好。但现在我希望能够从 XML 设置此属性的值。我可以使用字符串、int、引用格式创建自定义属性,但我看不到如何将此属性定义为MyCustomType格式。我想像这样的东西:
<declare-styleable name="MyCustomView">
<attr name="prop1" format="MyCustomType"/>
</declare-styleable>
这有可能吗?或者自定义类型属性只能从后面的代码中设置?
谢谢!