Search code examples
androidexceptioncolorsembedded-resourcexamarin.android

MonoDroid - setting background color from colors.xml throws InvalidOperationException


I have a simple layout as follows:

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout
  android:id="@+id/widget30"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@color/translucent_red"
  android:orientation="vertical"
  xmlns:android="http://schemas.android.com/apk/res/android">

My colors.xml file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="opaque_red">#f00</color>
  <color name="translucent_red">#80ff0000</color>
</resources>

When I compile in VS2010 I get an error "System.InvalidOperationException: Command failed...." I have tried to place the colors.xml in res/values and res/color but I still get the error. If I reference the color directly like:

android:background="#80ff0000"

everything works fine.

Does anyone know if the colors.xml is supported by MonoDroid and if so why I'm getting this error?

Thanks for the help!


Solution

  • Figured it out, the Build Action for colors.xml was set to Content instead of AndroidResource !