【问题标题】:Custom attributes in style样式中的自定义属性
【发布时间】:2015-01-23 14:51:55
【问题描述】:

在我当前的项目 styles.xml 中,我尝试定义:

<resources xmlns:ripple="http://schemas.android.com/apk/res-auto">
<resources xmlns:ripple="http://schemas.android.com/apk/res/com.gorkem.components">

我用这个:

<style name="FlatTextRipple">
    <item name="ripple:rv_centered">true</item>
    <item name="ripple:rv_color">#CCCCCC</item>
    <item name="ripple:rv_type">simpleRipple</item>
    <item name="ripple:rv_zoom">true</item>
    <item name="ripple:rv_zoomDuration">300</item>

</style>

在我的图书馆项目中,我有 attrs.xml:

<declare-styleable name="RippleView">
    <attr name="rv_alpha" format="integer" />
    <attr name="rv_framerate" format="integer" />
    <attr name="rv_rippleDuration" format="integer" />
    <attr name="rv_zoomDuration" format="integer" />
    <attr name="rv_color" format="color" />
    <attr name="rv_centered" format="boolean" />
    <attr name="rv_type" format="enum">
        <enum name="simpleRipple" value="0" />
        <enum name="doubleRipple" value="1" />
        <enum name="rectangle" value="2" />
    </attr>
    <attr name="rv_ripplePadding" format="dimension" />
    <attr name="rv_zoom" format="boolean" />
    <attr name="rv_zoomScale" format="float" />
</declare-styleable>

但我不明白 Í 什么时候像在它运行的布局中那样使用它,但是当我使用 style.xml 时,gradle 不能 attr 并且它给了我这个错误:

    Error:(6, 21) No resource found that matches the given name: attr 'ripple:rv_centered'.
    Error:(7, 21) No resource found that matches the given name: attr 'ripple:rv_color'.
    Error:(8, 21) No resource found that matches the given name: attr 'ripple:rv_type'.
    Error:(9, 21) No resource found that matches the given name: attr 'ripple:rv_zoom'.

【问题讨论】:

  • 你用双“O”写了
  • 我在我的代码中写错了它是正确的

标签: android android-gradle-plugin custom-attributes android-custom-attributes


【解决方案1】:

样式与您在布局中所做的不匹配。在您的 styles.xml 中,删除您的自定义 xmlns 声明,然后直接使用不带前缀的属性,如下所示:

<style name="FlatTextRipple">
    <item name="rv_centered">true</item>
    <item name="rv_color">#CCCCCC</item>
    <item name="rv_type">simpleRipple</item>
    <item name="rv_zoom">true</item>
    <item name="rv_zoomDuration">300</item>
</style>

【讨论】:

  • 为我工作。 API 23.
猜你喜欢
  • 1970-01-01
  • 2011-01-11
  • 2018-04-20
  • 2011-12-12
  • 1970-01-01
  • 2018-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多