Android Studio 中未找到 Theme.AppCompat.Light 资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24484216/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:17:11  来源:igfitidea点击:

Theme.AppCompat.Light resource not found in Android Studio

androidandroid-studioandroid-appcompat

提问by user3607131

When trying to extend ActionBarActivity I need to use the AppCompat theme (Theme.AppCompat.Light). When I try to add it in the manifest and styles.xml I get

在尝试扩展 ActionBarActivity 时,我需要使用 AppCompat 主题 (Theme.AppCompat.Light)。当我尝试将它添加到 manifest 和 styles.xml 我得到

Error:(31, 28) No resource found that matches the given name (at 'theme' with value '@android:style/Theme.AppCompat.Light').

错误:(31, 28) 找不到与给定名称匹配的资源(在“主题”处,值为“@android:style/Theme.AppCompat.Light”)。

Eventhough I have downloaded the support libraries and included this in my build.gradle file ->

尽管我已经下载了支持库并将其包含在我的 build.gradle 文件中 ->

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

回答by user1652110

In Android Studio, I had this same error when using android:theme='@android:style/Theme.AppCompat.Lightbut when I use android:theme="@style/Theme.AppCompat.Light"inside the AndroidManifest.xml file, the error is gone.

在 Android Studio 中,我在使用android:theme='@android:style/Theme.AppCompat.Light时遇到了同样的错误,但是当我android:theme="@style/Theme.AppCompat.Light"在 AndroidManifest.xml 文件中使用时,错误消失了。

The difference appears to be from referring to an Android system wide provided theme "@android", to a locally defined theme "@style". Using the locally defined theme works due to having defined the gradle dependency on the appcompat library compile 'com.android.support:appcompat-v7:19.0.+', which is imported as a local theme.

区别似乎是从 Android 系统范围提供的主题“@android”到本地定义的主题“@style”。由于在 appcompat 库上定义了 gradle 依赖关系,因此使用本地定义的主题可以工作,该库compile 'com.android.support:appcompat-v7:19.0.+'作为本地主题导入。

For reference, the official documentation from Google for Android Developers around adding the ActionBar on Android devices 2.1+ instructs to use: android:theme="@style/Theme.AppCompat.Light"https://developer.android.com/training/basics/actionbar/setting-up.html

作为参考,Google for Android Developers 关于在 Android 设备 2.1+ 上添加 ActionBar 的官方文档指示使用:https: android:theme="@style/Theme.AppCompat.Light"//developer.android.com/training/basics/actionbar/setting-up.html

回答by The Original Android

From Android Studio, different than Eclipse:

来自 Android Studio,不同于 Eclipse:

  1. Open the build.gradle file for your application.

  2. Include the appcompat project and add compile "com.android.support:appcompat-v7:18.0.+" to the dependencies section, as shown in the following example:

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

  3. My note: In styles.xml, remove the reference to Android as in:

    style name="AppTheme" parent="Theme.AppCompat.Light"

  1. 打开应用程序的 build.gradle 文件。

  2. 包含 appcompat 项目并将 compile "com.android.support:appcompat-v7:18.0.+" 添加到依赖项部分,如下例所示:

    依赖{ ...编译“com.android.support:appcompat-v7:18.0.+”}

  3. 我的笔记:在styles.xml中,删除对Android的引用,如下所示:

    样式名称="AppTheme" parent="Theme.AppCompat.Light"

For more details, read link

欲了解更多详情,请阅读链接

回答by iltaf khalid

Use Theme.AppCompat.Light instead of AppCompat.Theme.Light

使用 Theme.AppCompat.Light 而不是 AppCompat.Theme.Light

回答by Daniel Nyamasyo

What is happening is that the dependency responsible for that style is not being recognized.

正在发生的事情是无法识别负责该样式的依赖项。

just delete these from build.gradle if you have them:

如果你有它们,只需从 build.gradle 中删除它们:

'com.android.support:appcompat-v7:28.0.0'
'com.android.support:design:28.0.0'

then sync, then undo delete, then sync again.

然后同步,然后撤消删除,然后再次同步。

回答by seyed Jafari

Invalidate Caches/restart in the file menu always does the job for me

文件菜单中的无效缓存/重新启动总是为我做这项工作