2013-01-21 41 views
2

如果我有以下设置:使用自定义属性设置视图的子类的自定义属性?

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> 

如果我要继承了这一观点一个又一个,但仍然能够指定自定义的值XML中的属性,我该怎么做?

public class DEFView extends ABCView { 
    //implementation here 
} 

但是,当我尝试使用XML中的孩子看,我得到一个错误 - 它不能识别此属性适用,因为它似乎不知道有关Java类之间的关系。我该如何处理?

回答

2

由于XML不会涉及java类层次结构,因此您可能还需要为子类别视图指定显式的自定义属性。

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name = "DEFView" > 
     <attr name="foo" format="boolean"/> 
    </declare-styleable> 
</resources>