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

 今天在做一个程序时觉得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控件的背景色。

转载于:https://www.cnblogs.com/li-fei/p/4138879.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值