android常见错误之 No r… 分类: Android开发 2014-05-30 10:54 59人阅读 评论(0) 收藏

  今天在做一个程序时觉得TextView的背景色不好看,就想在xml文件中改变TextView的背景色。因为本人在 /res/values下放了一个colors.xml文件, 因此在xml文件中使用android:background="@colors/lightyellow"以图将TextView控件的背景色设置为亮黄色。结果出错:No resource found that matches the given name (at 'background' with value
 '@colors/lightyellow')。后来在网上搜寻解决方案,看到一高人发表如下高见:You should always reference @color. If you reference @colors, that'd be good. Basically, when you type @color, it goes to /res/values and looks through the XML files there for a color value. Thus, the name of the XML file is actually arbitrary, as long as you have it in /res/values.
意识是只要你的颜色文件放在/res/values 目录下不论你文件的文件名是什么,都要用@color方法引用,可能是因为它只看xml文件里有没有标签,不看文件名。受高人指点,改成android:background="@color/lightyellow"后果真没有错误,而且成功改变了TextView控件的背景色。

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-05-30 10:54  leansmall  阅读(106)  评论(0编辑  收藏  举报