17

如何正确使用 Android 支持库,因为我的清单文件中有此错误:

android:theme="@style/Theme.AppCompat.Light.DarkActionBar"

error: Error: No resource found that matches the given name 
(at 'theme' with value '@style/Theme.AppCompat.Light.DarkActionBar').
AndroidManifest.xml /ttab   line 39 Android AAPT Problem

我的朋友以前在其他计算机上为我完成了此操作,现在我必须单独执行此操作。请帮我:)

我正在使用 ADT

我的样式.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="android:Theme.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>

    <style name="Theme.AppCompat.Light">
     <!-- theme customizations here. -->
    </style>


    <style name="Theme.AppCompat.Light.DarkActionBar" parent="Theme.AppCompat.Light">
      <!-- theme customizations here. -->
    </style>


</resources>
4

5 回答 5

16

在“android-support-v7-appcompat”项目中:

  • 从包资源管理器中删除“android-support-v7-appcompat”。
  • 再次导入并勾选“复制到工作区”</li>
  • 在 Properties -> Android -> Project build target 中,取消选中 Android 2.2 并选中 Android 4.1.2
  • 在 Java 构建路径中,取消选中是否有任何 .jar 库,并取消选中 Dependences

另一方面,使用“android-support-v7-appcompat”的项目:

  • 在 Properties -> Android 添加库,但取消选中“IsLibrary”。
  • 在 Android -> Project build tarjet 中检查 Android 4.0。
  • 在“Java 构建路径”-> 订购和导出-> 取消选中 .jar 库
  • 最后做一个“项目->清理”两个项目
于 2013-11-19T17:49:47.413 回答
7

如果您使用的是 Gradle,那么您在使用最新版本的兼容性库时会遇到问题。

如果您的build.gradle文件中有以下内容,'+'最后带有 a:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}

那么它可能会获取比您想要的更高版本的库。

将依赖项更改为:

dependencies {
    compile 'com.android.support:appcompat-v7:18.0+'
}

可能会解决您的问题。

于 2014-06-30T16:46:15.400 回答
5

你能试试吗

android:theme="Theme.AppCompat.Light.DarkActionBar"

代替

android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
于 2014-08-08T13:59:02.020 回答
0
  1. 转到您的项目目录(或项目视图)
  2. 查找并打开 .idea 目录
  3. 删除缓存和库目录<-这是必不可少的
  4. 使缓存无效/重新启动
于 2019-03-29T05:13:12.193 回答
0

在您的应用程序依赖项文件中检查您是否具有依赖项

compile 'com.android.support:appcompatv[anything here]

或者

implement 'com.android.support:appcompat[anything here]

删除或注释掉它们,单击“灯泡”以获取自动建议,然后选择添加库依赖项。 点击 appcompat 的 autofillbulb

滚动第一个版本的 appcompat 的选项。该库将添加到依赖项列表下方。重建应用程序或使缓存无效并重新启动

在一种情况下,这不起作用,转到包含项目的文件夹,删除 .gradle 文件并重新启动 Android Studio 已经奏效。从https://reformatcode.com/code/android/error-while-gradle-sync中的Sneh Pandya 的答案中得到

于 2018-01-16T15:55:12.963 回答