开发者

MonoDroid - setting background color from colors.xml throws InvalidOperationException

开发者 https://www.devze.com 2023-02-05 17:11 出处:网络
I have a simple layout as follows: <?xml version=\"1.0\" encoding=\"utf-8\"?> <LinearLayout android:id=\"@+id/widget30\"

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.andr开发者_运维百科oid.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!


Good you found this out. Another issue point to take into account is that you always define the color id's with lowercase letters. I used capital casing and although my c# code finds the resources with case sensitive searching, android expects lowercase id's when referring from drawable or layout xml files (using @color/the_id_here).


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号