0

In my Android project I have a custom view with a custom property. Setting the property works fine:

<com.mycompany.CustomView
    [...]
    mycompany:myproperty="myvalue"
/>

What I want to do is set the property in a style, so that I have a style like this:

<style name="CustomViewStyle">
    <item name="mycompany:myproperty">myvalue</item>
</style>

And change the custom view declaration to this:

<com.mycompany.CustomView
    [...]
    style="@style/CustomViewStyle"
/>

However, this results in the build error No resource found that matches the given name: attr 'mycompany:myproperty'. Adding the namespace declaration xmlns:mycompany="http://schemas.android.com/apk/res-auto" to style.xml does not help. Is there a way to make this work?

1 Answer 1

1

I believe you should set your custom style like this

<style name="CustomViewStyle">
    <item name="myproperty">myvalue</item>
</style>
Sign up to request clarification or add additional context in comments.

3 Comments

I have done this. As I wrote in my question, setting the style on the actual element works fine, it's when I try to set it in a style that I have a problem.
I am sorry that I misunderstood before. Updating my answer.
Perfect, that works! Don't know why I didn't try that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.