风格中的自定义属性

时间:2014-11-25 14:37:00

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

在我当前的项目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'.

1 个答案:

答案 0 :(得分:6)

样式与布局中的样式不匹配。在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>
相关问题