Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Create one style in style.xml with attributes of a library

Guys I need help.

I have a project with a library called MaterialRipple, and this library solved my problem, but the code that I have to use in each view is very extensive and if one day I have to do maintenance it will take a lot of work, so I decided to put the whole When I compile the code in a style tag, but when I compile it appears the error "No resource found that matches the given name: attr 'local: mrl_ripplePersistent'" and this happens for all other attributes included in my style tag.

my tag style in style.xml

    <style name="wave_effect">
    <item name="android:layout_centerInParent">false</item>
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="local:mrl_rippleOverlay">true</item>
    <item name="local:mrl_rippleColor">#F0F0F0</item>
    <item name="local:mrl_rippleAlpha">0.1</item>
    <item name="local:mrl_rippleDimension">10dp</item>
    <item name="local:mrl_rippleHover">true</item>
    <item name="local:mrl_rippleRoundedCorners">10dp</item>
    <item name="local:mrl_rippleInAdapter">false</item>
    <item name="local:mrl_rippleDuration">350</item>
    <item name="local:mrl_rippleFadeDuration">75</item>
    <item name="local:mrl_rippleDelayClick">true</item>
    <item name="local:mrl_ripplePersistent">false</item>                
    </style>

Error:

    Error       No resource found that matches the given name: attr 'local:mrl_ripplePersistent'.
    Error       No resource found that matches the given name: attr 'local:mrl_rippleColor'.
    Error       No resource found that matches the given name: attr 'local:mrl_rippleDuration'. 
    Error       No resource found that matches the given name: attr 'local:mrl_rippleHover'.    
    Error       No resource found that matches the given name: attr 'local:mrl_rippleAlpha'.    
    Error       No resource found that matches the given name: attr 'local:mrl_rippleInAdapter'.        
    Error       No resource found that matches the given name: attr 'local:mrl_rippleOverlay'.      
    Error       No resource found that matches the given name: attr 'local:mrl_rippleRoundedCorners'.   
    Error       No resource found that matches the given name: attr 'local:mrl_rippleDelayClick'.   
    Error       No resource found that matches the given name: attr 'local:mrl_rippleDimension'.    
    Error       No resource found that matches the given name: attr 'local:mrl_rippleFadeDuration'.

Posts

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    You will want to declare attributes for your custom widget. There's an example of material ripple here:

    https://github.com/balysv/material-ripple/blob/master/library/src/main/res/values/attributes.xml

    You will then need to declare an attribute for a style reference:

    <declare-styleable name="CustomTheme">
        <attr name="customMaterialRippleLayoutStyle" format="reference"/>
    </declare-styleable>
    

    Once you've done that, you now need two different things:

    1) A style for the control's properties

    <style name="Widget.MaterialRippleLayout.Custom">
        <item name="customAttr">some value</item>
    </style>
    

    2) A theme that takes in the control style and sets it

    <style name="Theme.Custom" parent="@android:style/Theme">
        <item name="customMaterialRippleLayoutStyle">@style/Widget.MaterialRippleLayout.Custom</item>
    </style>
    

    You then need to apply that theme to any activity that uses the custom control.

  • PeterNovassatPeterNovassat USMember ✭✭

    Thank you very much Jon Douglas, that's exactly what I needed.

Sign In or Register to comment.