我有一个复合控件,它本质上结合了Button
和ProgressBar
。它包括一个背景属性,我在attrs.xml中声明为:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<declare-styleable name="MyControl">
<attr name="background" format="reference" />
</declare-styleable>
</resources>
在我的控件的构造函数中,我从TypedArray
中提取背景并应用它
所有这些都很好,直到最近,我不得不添加对v4支持库的依赖。现在我在attrs.xml文件中得到了这个构建错误:
错误APT0000:属性"背景"已定义(APT0000)
为什么会这样?作为替代方案,我能做些什么,让我的复合控件的消费者可以设置背景?
这与定义"background"属性的内部库有冲突。有关更多详细信息,请访问:https://groups.google.com/forum/#!topic/actionbarsherlock/N0hn47zx6w
属性"background"已经在支持库中定义。所以你不必再定义它了。你只需要添加属性而不定义它,就像这样,
如果你想在自定义视图中使用app:background,那么在attrs文件中<attr name="background"/>
就足够了。
如果你想在自定义视图中使用android:background,那么在attrs中使用这一行。
<attr name="android:background"/>