Questions tagged «android-custom-attributes»

5
attrs.xml中用于自定义视图的同名属性
我正在写一些共享一些同名属性的自定义视图。在它们各自的<declare-styleable>部分中,attrs.xml我想对属性使用相同的名称: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView1"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> <declare-styleable name="MyView2"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> </resources> 我在说一个错误myattr1并且myattr2已经定义了。我发现我应该省略和中的format属性,但是如果这样做,我会在控制台中收到以下错误:myattr1myattr2MyView2 [2010-12-13 23:53:11 - MyProject] ERROR: In <declare-styleable> MyView2, unable to find attribute 有什么办法可以做到这一点,也许是某种命名空间(只是猜测)?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.