No resource found that matches the given name 'android:WindowTitle'

当你的androidAPI 由2.1版本更换成2.2版本时:
 res/vavlues/styles.xml中使用的android:WindowTitle会报如下异常,
error: Error retrieving parent for item: No resource found that matches the given name 'android:WindowTitle'.
从而致使咱们的程序没法编译经过。
 
缘由:
android2.1中的某些API(包括类方法或者XML属性)更换成android2.2时,它们的路径已经发生了改变,从而致使编译器没法找到它们,因此编译没法经过。
 
 

解决方案:html

1. 在Eclipse中打开任意一个.java文件,输入
    android.R.style.
   这时你会看到一个提示列表,仔细看看,里面确实没由WindowTitle, 可是咱们发现了一个TextAppearance_WindowTitle. 没错, 在android2.2中,它已经被改为了 TextAppearance_WindowTitle
 
2. 回到报错的res/values/styles.xml, 将<style name="XWindowTitle" parent=""> 
   相应地修改为
  <style name="XWindowTitle" parent=" android:TextAppearance.WindowTitle">
 
  注意:这里你也许会注意到 .java文件中的XML属性,与 .xml文件中XML属性非常相似。
  这不是巧合,android官方文档规定:
  java文件中的 android.R.style.TextAppearance_WindowTitle 对应
  xml文件中的android:TextAppearance.WindowTitle。 “下划线”与“点”时对应关系。
 
关于Styles and Themes 之间的关系,请参考官方网站
相关文章
相关标签/搜索