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

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

问题描述:

尝试扩展 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) 找不到与给定名称匹配的资源(位于'theme' 值为 '@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.

作为参考,Google for Android Developers 关于在 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