我有一个简单的布局如下:
<?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">
我的colors.xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<color name="translucent_red">#80ff0000</color>
</resources>
当我在VS2010中编译时,我收到错误“System.InvalidOperationException:Command failed ....”我试图将colors.xml放在res / values和res / color中,但我仍然 得到错误。如果我直接引用颜色,如:
android:background="#80ff0000"
一切正常。
有没有人知道MonoDroid是否支持colors.xml,如果是,为什么我会收到此错误?
感谢您的帮助!
答案 0 :(得分:2)
很好,你发现了这一点。另一个值得考虑的问题是,您始终使用小写字母定义颜色ID。我使用了大写套管,虽然我的c#代码找到了区分大小写搜索的资源,但是当从drawable或layout xml文件引用时,android需要小写的id(使用@ color / the_id_here)。
答案 1 :(得分:1)
想出来,colors.xml的Build Action设置为Content而不是AndroidResource!