(一)

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

(二)

这类问题在于当工程导入eclipse时软件默认配置的build target的版本低于代码中使用的版本,例如上面的第3个错误,android:fontFamily 是在 API Level 16 才支持的,如果 build target 配置的版本低于16就会报错了。

解决方法是打开工程的属性对画框-> Android (Project Build Target) ->选择不低于代码中对应使用的API,问题即可解决。

(三)

不仅要编译版本,最小运行版本也要兼容

检查一下AndroidManifest.xml里android:minSdkVersion

(四)

图片资源格式不能乱改,如果将一个其他图片改为Png,解析的时候就会错误,因为实际格式没改

(五)

缺少必要的资源包

新建立一个android 工程,发现 在 style.xml 文件中报 "error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.错误 可能是缺少 Theme.AppCompat.Light 这个主题资源,发现是缺少 android-support-v7 资源包导致。 解决方法 找到android-support-v7 资源路径 SDK_PATH/extras/android/support/v7 右键项目->properites->android->右下角 Library add android-support-v7 资源包路径->apply 即引入资源包,问题解决.

(六)

jar包和引入support library是不同的

比如support_r22.2.zip这个包,解压后,许多工程并不仅仅是需要v7 jar包,仅仅引入jar出错,需要完整的工程引用,可能连工程中的资源文件也可以直接拿来

/android-support-v7-appcompat

library    add   


更多相关文章

  1. 修改Android Studio默认配置文件路径
  2. Android XML文件中的@、?、@+的该怎么理解?
  3. android studio开发环境配置(指定SDK及卸载)附安装文件网盘地址(win
  4. Android所有可用的资源列表
  5. 【Android】Eclipse上安装CDT配合MinGW,解决新建工程时找不到MinG
  6. Android编译过程总结及android中各种img文件的作用以及系统启动

随机推荐

  1. Python英语-Issue08
  2. 这次简单多了,最新版 MongoDB 安装
  3. spring boot 上传文件到指定目录
  4. 第100篇原创,新的起点
  5. java 手写文字图片识别提取 百度API
  6. Python英语 - Issue13
  7. Bokeh中图形与组件的布局简介 | Bokeh 小
  8. 不再被坑,Jupyter Notebook 输出pdf并支持
  9. Python英语 - Issue14
  10. 还在吐槽 Jupyter Notebook 的默认风格?