Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 753
Brian Mains Avatar asked Jul 22 '13 02:07

Brian Mains


Video Answer


2 Answers

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.

like image 116
Cheesebaron Avatar answered Sep 21 '22 22:09

Cheesebaron


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

like image 34
Blasco73 Avatar answered Sep 20 '22 22:09

Blasco73