Brian Mains
Brian Mains

Reputation: 50728

Xamarin Colors Causing Build Errors

I have an android application built with Xamarin Studio. I added a file named colors.xml to the Resources/values folder. The contents were:

<resources>
    <color name="ViewBackgroundColor">#ffffff</color>
</resources>

To that, I was following this approach to define and use it; however, I was trying to apply it to the view's root element (found that resource elsewhere on SO, don't have exact link). So I applied it to the view by adding android:background="@color/ViewBackgroundColor" attribute to the root element. However, this generates a build error that @color/ViewBackgroundColor isn't a value. is anybody else having this issue and is there a resolution?

Upvotes: 5

Views: 2991

Answers (2)

Blasco73
Blasco73

Reputation: 2990

Is also important to set "Build Action" (with mouse right button on file color.xml) as AndroidResource.

Upvotes: 1

Cheesebaron
Cheesebaron

Reputation: 24460

To reference that color, you must use all lowercase letters.

So

android:background="@color/viewbackgroundcolor"

This is because the Xamarin tools lowercases all names to be compliant with the rules Android has for resource names.

Upvotes: 8

Related Questions