【问题标题】:Background property on custom compound control自定义复合控件的背景属性
【发布时间】:2016-05-03 03:46:04
【问题描述】:

我有一个复合控件,它基本上结合了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)

这是为什么?我可以做些什么来替代我的复合控件的使用者可以设置背景?

【问题讨论】:

    标签: java android controls


    【解决方案1】:

    这与也定义了“背景”属性的内部库发生冲突。 更多详情请访问:https://groups.google.com/forum/#!topic/actionbarsherlock/_N0hn47zx6w

    【讨论】:

      【解决方案2】:

      “背景”属性已在支持库中定义。所以你不必再次定义它。您只需添加属性而不定义它,就像这样,

      如果你想在自定义视图中使用 app:background,那么 &lt;attr name="background"/&gt; 在 attrs 文件中就足够了。

      如果你想在自定义视图中使用 android:background,那么在 attrs 中使用这一行。

      <attr name="android:background"/>
      

      【讨论】:

      • 将&lt;attr name="background"/&gt; 放入我的 attrs.xml 正是我正在尝试的,并且是什么给了我编译错误。
      猜你喜欢
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多