如果我有以下设置:
public class ABCView extends View {
//implementation here
}
具有以下自定义属性:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name = "ABCView" >
<attr name="foo" format="boolean"/>
</declare-styleable>
</resources>
如果我想用另一个 View 子类化此 View ,但仍然能够在 XML 中指定自定义属性的值,我该怎么做?
public class DEFView extends ABCView {
//implementation here
}
但是当我尝试在 XML 中使用 subview 时,出现错误 - 它无法识别该属性适用,因为它似乎不知道 java 类之间的关系。我该如何处理这个问题?
最佳答案
由于 XML 不涉及 java 类层次结构,因此您可能还需要为子类 View 显式指定自定义属性。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name = "DEFView" >
<attr name="foo" format="boolean"/>
</declare-styleable>
</resources>
关于android - 使用自定义属性设置View子类的自定义属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432178/