2

属性,在我目前的项目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和它gi给我这个错误:

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'. 
+0

你写* *双“O” – Rami 2014-11-25 14:56:47

+0

我写到这里的错我的代码是正确的 – 2014-11-25 15:18:24

回答

4

样式不匹配你在布局中做什么。在你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> 
+1

嘿巴迪,它不工作。 – 2017-04-19 10:02:17