码迷,mamicode.com
首页 > 移动开发 > 详细

android常见错误之 No resource found that matches the given name

时间:2014-12-03 00:23:47      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:android   ar   color   使用   sp   for   on   文件   bs   

 今天在做一个程序时觉得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文件里有没有<color></color>标签,不看文件名。受高人指点,改成android:background="@color/lightyellow"后果真没有错误,而且成功改变了TextView控件的背景色。

android常见错误之 No resource found that matches the given name

标签:android   ar   color   使用   sp   for   on   文件   bs   

原文地址:http://www.cnblogs.com/li-fei/p/4138879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!