2012-02-06 134 views
0

我创建了许多自定义视图,并且任何视图都有自定义属性:mystyle。在Android中如何在自定义视图之间共享attrs

让我attr.xml:

<resources> 
    <declare-styleable name="MyView1"> 
     <attr name="mystyle" format="string" /> 
    </declare-styleable> 
    <declare-styleable name="MyView2"> 
     <attr name="mystyle" format="string" /> 
    </declare-styleable> 
    <declare-styleable name="MyView2"> 
     <attr name="mystyle" format="string" /> 
    </declare-styleable> 
    ... 
</resources> 

我认为这不是风度。对于所有的客户视图,有没有办法使用一个attr?

回答

1

您可以尝试制作abstract ParentView并为其声明属性。然后,您所有的自定义视图将延伸ParentView,并且属性将被声明为

相关问题