java - 操作栏V7 : Why it doesn't work?

标签 java android xml

我正在尝试将 ActionBar V7 包含在我的应用程序中。在 AndroidManifest.xml 中我放入

android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

在值/style.xml中

    <resources>

        <!--
            Base application theme, dependent on API level. This theme is replaced
            by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
        -->
        <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
            <!--
                Theme customizations available in newer API levels can go in
                res/values-vXX/styles.xml, while customizations related to
                backward-compatibility can go here.
            -->

    </style>
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">

            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        </style>

</resources>

在值-v11中

<?xml version="1.0"?>
-<resources>
<!-- Base application theme for API 11+. This theme completely replaces AppBaseTheme from res/values/styles.xml on API 11+ devices. -->
-<style parent="Theme.AppCompat.Light" name="AppBaseTheme">
<!-- API 11 theme customizations can go here. -->
</style></resources>

在values-v14中

<resources>

    <!--
        Base application theme for API 14+. This theme completely replaces
        AppBaseTheme from BOTH res/values/styles.xml and
        res/values-v11/styles.xml on API 14+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!-- API 14 theme customizations can go here. -->
    </style>

</resources>

在我放置的 Activity 中

import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity

执行后告诉我项目中有错误。准确地说,这些错误都在 style.xml 中,并且错误是“错误:检索项目父级时出错:找不到与给定名称“Theme.AppCompat.Light”匹配的资源。 “为什么我有这个错误以及如何修复它?我将库 android-support-v7-appcompat.jar 放在/libs 中,然后右键单击将其添加到 Build Patch。我也尝试重新启动 eclipse,但它不起作用一样。

最佳答案

v7 appcompat 库包含除 JAR 文件之外的资源。可以在此处找到包含资源库的说明:

http://developer.android.com/tools/support-library/setup.html#add-library

使用资源添加库 - 使用 Eclipse

关于java - 操作栏V7 : Why it doesn't work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19432074/

相关文章:

java - 将字段转换为 HashMap

xml - 获取 XSL 中的最后几个节点,跨越父节点

java - Apache PDFBox : Get alignment and font from a PDAnnotationWidget or PDTextField

java - Spring 响应式(Reactive)事务在取消时提交,产生部分提交

java - Android try/catch 不起作用

java - 从mysql数据库解析数据时出错

java - 在 touch-LibGdx 上将对象数组元素补间到一个角

python - simplexml_load_string 等效于 Python/Django

c# - .NET XmlDocument : Why DOCTYPE changes after Save?

java - 当 Internet Explorer 工作正常时,Firefox 和 Chrome 在文件名前后附加下划线