eclipse新建android工程style文件里的Theme总是报错

eclipse新建android工程style文件里的Theme总是报错

报错如下:

Description Resource Path Location Type error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.styles.xml  /simplejni/res/values  line 7  Android AAPT Problem

values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.

values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.

values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.

在网上搜索好久, 总结:
方法一:


查看 res/values/styles.xml 下的报错点。
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
把这个改成
<style name="AppBaseTheme" parent="android:Theme.Light">

路径: res/values-11/styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
把这个改成
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">

路径: res/values-14/styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
把这个换成
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
注意:
    因为res/values/styles.xml下的style是兼容最低android版本的,所以res/values-11/styles.xml和res/values-14/styles.xml下的AppBaseTheme为了适应更高版本的样式,不能直接设置成android:Theme.Light,不然最终显示的样式都是最低android版本的。但是改完后又会有其它地方报错,所以感觉并不可取,可以尝试下。

方法二:

上述报错是由于导入的工程未加入android.support:appcompat-v7兼容包,因为AppCompat是属于appcompat-v7中的,解决办法如下:
1.导入android.support:appcompat-v7兼容包,它在你的XXX\sdk\extras\android\support\v7\appcompat路径下,File——>Import——>Android——>Existing Android Code Into Workspace,点击Next。
eclipse新建android工程style文件里的Theme总是报错
点击Browse选择v7 appcompat路径,注意要选中Copy projects into workspace选项,点击Finish,导入成功。
eclipse新建android工程style文件里的Theme总是报错eclipse新建android工程style文件里的Theme总是报错

2.在原先打开的工程中添加android-support-v7-appcompat.jar库,右击原来的项目,Properties——>Android,在Library中点击Add,选择android-support-v7-appcompat,点击OK。
eclipse新建android工程style文件里的Theme总是报错

eclipse新建android工程style文件里的Theme总是报错

这样返回时看见Library中已经加入了,点击Apply,这样在项目文件中的Android Private Libraries中看见新增加了android-support-v7-appcompat.jar,可以先Project——>Clean一下,再点击编译运行就没问题了。

eclipse新建android工程style文件里的Theme总是报错


注意:在导入原来的项目时,也要选中Copy projects into workspace选项!!!

eclipse新建android工程style文件里的Theme总是报错