zoukankan      html  css  js  c++  java
  • 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控件的背景色。

  • 相关阅读:
    contextMenu,右键菜单
    hashchange
    web攻击日志分析之新手指南
    工匠人生
    数学有卵用之通信篇
    精英主义(一)
    flaskbb部署笔记
    深入分析一波,你们说的云安全到底是什么鬼?
    Gh0st与云安全
    困境与突破
  • 原文地址:https://www.cnblogs.com/li-fei/p/4138879.html
Copyright © 2011-2022 走看看