Android Studio 中未找到 Theme.AppCompat.Light 资源 [英] Theme.AppCompat.Light resource not found in Android Studio

查看:62
本文介绍了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

这篇关于Android Studio 中未找到 Theme.AppCompat.Light 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆