Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom attributes in style

In my current project styles.xml I try to define:

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

and I use this:

<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>

and in my library project I have 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>

But I don't understand when Í use it like in layout it is running but when I use style.xml gradle can not attr and it gives me this error :

    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'.
like image 887
Görkem Karadoğan Avatar asked Nov 25 '14 14:11

Görkem Karadoğan


People also ask

What are custom attributes?

A custom attribute is a property that you can define to describe assets. Custom attributes extend the meaning of an asset beyond what you can define with the standard attributes. You can create a custom attribute and assign to it a value that is an integer, a range of integers, or a string.

Can we use custom attributes?

Custom attributes are attributes that are not part of the standard HTML5 attributes but are explicitly created. They allow us to add our own information to HTML tags. These are not specific and can be used with all the HTML elements.

What is custom attribute in C#?

Attributes are used to impose conditions or to increase the efficiency of a piece of code. There are built-in attributes present in C# but programmers may create their own attributes, such attributes are called Custom attributes. To create custom attributes we must construct classes that derive from the System.

What are custom attributes in square?

Custom attributes are a lightweight way to include additional properties in a Square data model. You can use custom attributes to extend Square's data model to make it more specific to the business problem you are trying to solve.


1 Answers

Styles don't match what you do in layouts. In your styles.xml, remove your custom xmlns declaration, and just use the attributes directly with no prefix, like so:

<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>
like image 118
Kevin Coppock Avatar answered Oct 30 '22 14:10

Kevin Coppock