在Android Studio中找不到Theme.AppCompat.Light资源 [英] Theme.AppCompat.Light resource not found in Android Studio
问题描述
当尝试扩展ActionBarActivity时,我需要使用AppCompat主题(Theme.AppCompat.Light).当我尝试将其添加到manifest和styles.xml中时,我得到了
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
错误:(31,28)找不到与给定名称匹配的资源(位于 值"@android:style/Theme.AppCompat.Light"的主题".
Error:(31, 28) No resource found that matches the given name (at 'theme' with value '@android:style/Theme.AppCompat.Light').
虽然我已经下载了支持库并将其包含在我的build.gradle文件中->
Eventhough I have downloaded the support libraries and included this in my build.gradle file ->
dependencies {
compile 'com.android.support:appcompat-v7:19.0.+'
compile 'com.android.support:support-v4:19.0.+'}
推荐答案
在Android Studio中,使用android:theme='@android:style/Theme.AppCompat.Light
时出现相同的错误,但是当我在AndroidManifest.xml文件中使用android:theme="@style/Theme.AppCompat.Light"
时,该错误消失了.
In Android Studio, I had this same error when using android:theme='@android:style/Theme.AppCompat.Light
but when I use android:theme="@style/Theme.AppCompat.Light"
inside the AndroidManifest.xml file, the error is gone.
区别似乎是从引用Android系统范围内提供的主题"@android"到本地定义的主题"@style".使用本地定义的主题之所以可行,是因为已对appcompat库compile 'com.android.support:appcompat-v7:19.0.+'
定义了gradle依赖关系,该库已作为本地主题导入.
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 2.1+设备上添加ActionBar的官方文档要求使用:android:theme="@style/Theme.AppCompat.Light"
https://developer.android.com/training/basics/actionbar/setting-up.html
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
这篇关于在Android Studio中找不到Theme.AppCompat.Light资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!