Java Theme.AppCompat.Light.DarkActionBar - 找不到资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18364682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Theme.AppCompat.Light.DarkActionBar - No resource found
提问by Jerry
How to use properly Android Support Library because i have this error in my manifest file:
如何正确使用 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
My friend did this implementing for me previously on other computer, now i have to do this alone. Please help me:)
我的朋友以前在其他计算机上为我做过这个实现,现在我必须一个人做这个。请帮我:)
I am using ADT
我正在使用 ADT
My styles.xml:
我的styles.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>
回答by Hernaldo Gonzalez
In "android-support-v7-appcompat" project:
在“android-support-v7-appcompat”项目中:
- Delete “android-support-v7-appcompat” from Package explorer.
- Import again and check “Copy into workspace”
- In Properties -> Android -> in Project build target, uncheck Android 2.2 and check Android 4.1.2
- In Java build path, uncheck if you have any .jar library, and uncheck the Dependences
- 从包浏览器中删除“android-support-v7-appcompat”。
- 再次导入并勾选“复制到工作区”
- 在 Properties -> Android -> 在 Project build target 中,取消选中 Android 2.2 并选中 Android 4.1.2
- 在 Java 构建路径中,取消选中是否有任何 .jar 库,并取消选中依赖项
In other hand, the project that uses “android-support-v7-appcompat”:
另一方面,使用“android-support-v7-appcompat”的项目:
- In Properties -> Android add the library, but uncheck "IsLibrary”.
- In Android -> Project build tarjet check Android 4.0.
- In "Java Build Path" -> Order and Export -> Unchecked the .jar library
- Finally do a “Project -> Clean” both projects
- 在属性 -> Android 添加库,但取消选中“IsLibrary”。
- 在 Android -> Project build tarjet 检查 Android 4.0。
- 在“Java Build Path” -> Order and Export -> 取消选中 .jar 库
- 最后做一个“项目->清理”这两个项目
回答by ZenBalance
If you are using Gradle, then you have a problem with the latest version of the compatibility library.
如果您使用的是 Gradle,那么您在使用最新版本的兼容性库时会遇到问题。
If you have the following in your build.gradle
file with a '+'
at the end:
如果您的build.gradle
文件中有以下内容,并以 a'+'
结尾:
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
then it may be grabbing a later version of the library than you want.
那么它可能会抓取比您想要的更高版本的库。
Changing the dependency to:
将依赖更改为:
dependencies {
compile 'com.android.support:appcompat-v7:18.0+'
}
may fix your problem.
可能会解决您的问题。
回答by 0rland
Could you please try
你能试试吗
android:theme="Theme.AppCompat.Light.DarkActionBar"
instead of
代替
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
回答by simiyu
In your app dependencies file check if you have the dependency
在您的应用程序依赖项文件中检查您是否有依赖项
compile 'com.android.support:appcompatv[anything here]
or
或者
implement 'com.android.support:appcompat[anything here]
delete or comment them out, click on the "lightbulb" for auto-suggestions and choose add a library dependency. clicking on the autofillbulb for appcompat
删除或注释掉它们,单击“灯泡”进行自动建议,然后选择添加库依赖项。 单击 appcompat 的 autofillbulb
Scroll the options for the first version of appcompat. The library will be added below the list of dependencies. Rebuild the app or invalidate caches and restart
滚动第一版 appcompat 的选项。该库将添加到依赖项列表下方。重建应用程序或使缓存无效并重新启动
In one case this has not worked and going to the folder containing the project, deleting the .gradle file and restarting Android Studio has worked. Got from Sneh Pandya's answer in https://reformatcode.com/code/android/error-while-gradle-sync
在一种情况下,这不起作用,转到包含项目的文件夹,删除 .gradle 文件并重新启动 Android Studio 已起作用。来自 Sneh Pandya 在https://reformatcode.com/code/android/error-while-gradle-sync 中的回答
回答by Pradeep Kumar S
- Go to your project directory (or to Project View)
- Find and open .idea directory
- Remove caches and libraries directories <-- this is essential
- Invalidate Caches / Restart
- 转到您的项目目录(或项目视图)
- 查找并打开 .idea 目录
- 删除缓存和库目录 <-- 这是必不可少的
- 使缓存无效/重新启动