在项目中检索项目的父项时出错:'Theme.AppCompat.Light'

时间:2014-10-27 10:48:59

标签: android eclipse android-support-library android-theme android-actionbaractivity

我正在尝试在我的项目中使用ActionBarActivity。我按照https://developer.android.com/tools/support-library/setup.html#

中的说明将android-support-v7-appcompat导入工作区

我可以将appcompat项目添加为当前项目(eclipse)中的库。

Got the Green tick mark

现在使用以下import语句时没有错误。

import android.support.v7.app.ActionBarActivity;

当我从ActionBarActivity扩展我的类时没有错误。

public class MyClass extends  ActionBarActivity implements ActionBarListener  {....} 

但是,我在使用AppCompat样式时遇到错误。

在清单中,

<activity
        android:name=".Activity1"
        android:label="@string/app_name"
        android:screenOrientation="portrait" 
        android:theme="@style/AppTheme"
        >
        ....

    </activity>

在styles.xml中,

<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->

</style>


<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

使用parent =“Theme.AppCompat.Light”时,styles.xml中出现以下错误 **错误:检索项目的父项时出错:找不到与给定名称“Theme.AppCompat.Light”匹配的资源。**

为什么我无法从appcompat支持库访问资源。

P.s:我没有使用过android:showAsAction="never"

我的应用程序项目和appcompat都在同一个文件夹中(我将它们都复制到当前工作区)。

2 个答案:

答案 0 :(得分:6)

尝试使用此

替换Style.xml
<style name="AppBaseTheme" parent="android:Theme.Light">

而不是

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">

答案 1 :(得分:1)

只使用styles.xml进行了一些小改动

更改

 <style name="AppBaseTheme" parent="android:Theme.AppCompat">
    ...
</style>

<style name="AppBaseTheme" parent="@style/Theme.AppCompat">
    ...
</style>