无法为新的Android ActionBar支持找到Theme.AppCompat.Light

本文翻译自:Can't Find Theme.AppCompat.Light for New Android ActionBar Support

I am trying to implement the new ActionBar support library that was released by Google a couple days ago. 我正在尝试实施Google几天前发布的新ActionBar支持库。 In the past, I have successfully implemented ActionBarSherlock without any issues using the same method listed on Google Developer's Support Library Setup page - using the guide on how to include the resources (which is similar to how ActionBarSherlock did it). 在过去,我使用Google Developer's Support Library Setup页面上列出的相同方法成功实现了ActionBarSherlock,没有任何问题 - 使用有关如何包含资源的指南(类似于ActionBarSherlock的工作方式)。 I have the library project loaded in to my own project as a library as well. 我将库项目作为库加载到我自己的项目中。

I can tell the library is loading fine. 我可以告诉图书馆加载正常。 When, instead of extending Activity on my MainActivity.java, I changed it to extend ActionBarActivity (as per Google's instructions), no errors occur - and it imports correctly. 什么时候,我没有在MainActivity.java上扩展Activity,而是将其更改为扩展ActionBarActivity(根据Google的说明),没有错误发生 - 并且它正确导入。

I even tried bypassing the style.xml file and adding @style/Theme.AppCompat.Light directly in to the AndroidManifest.xml for both <application> and <activity> with android:theme="@style/ThemeAppCompat.Light" with all attempts resulting in the same error. 我甚至尝试绕过style.xml文件并将@style/Theme.AppCompat.Light直接添加到AndroidManifest.xml中,同时将<application><activity>android:theme="@style/ThemeAppCompat.Light"一起添加到所有尝试导致相同的错误。

Now the issue is I cannot get it to change the theme, let alone even build without throwing an error. 现在问题是我无法让它改变主题,更不用说甚至构建而不会抛出错误。 Below is the error I am receiving, followed by the style.xml file I changed to use the new theme. 下面是我收到的错误,后面是我更改为使用新主题的style.xml文件。

I have moderate experience working with Android apps and am running Eclipse with the latest version of the Support Libraries and SDK compiling with API 18 (Android 4.3). 我有使用Android应用程序的适度经验,并且使用最新版本的支持库和使用API​​ 18(Android 4.3)编译的SDK运行Eclipse。

Error Received During Build 构建期间收到错误

error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light'. 错误:检索项目的父项时出错:找不到与给定名称“@ style / Theme.AppCompat.Light”匹配的资源。 styles.xml /ActBarTest/res/values line 3 Android AAPT Problem styles.xml / ActBarTest / res / values line 3 Android AAPT问题

style.xml style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ProsoftStudio.ACTest" parent="@style/Theme.AppCompat.Light">
    </style>
</resources>

Any suggestions? 有什么建议? This was never an issue with ActionBarSherlock. 这从来都不是ActionBarSherlock的问题。 I want to work on using this new support library. 我想继续使用这个新的支持库。 It almost seems like the .jar is loading, but not the resources. 几乎看起来.jar正在加载,但不是资源。


#1楼

参考:https://stackoom.com/question/1Cz21/无法为新的Android-ActionBar支持找到Theme-AppCompat-Light


#2楼

你需要参考$ ANDROID_SDK / extras / android / support / v7 / appcompat


#3楼

You need to do next: 你需要做下一个:

  1. File->Import (android-sdk\\extras\\android\\support\\v7) . File->Import (android-sdk\\extras\\android\\support\\v7) Choose "AppCompat" 选择“AppCompat”
  2. Project-> properties->Android. In the section library "Add" and choose "AppCompat" 在“添加”部分库中选择“AppCompat”
  3. That is all! 就这些!

Note: if you are using "android:showAsAction" in menu item, you need to change prefix android as in the example http://developer.android.com/guide/topics/ui/actionbar.html 注意:如果您在菜单项中使用“android:showAsAction”,则需要更改前缀android,如示例http://developer.android.com/guide/topics/ui/actionbar.html


#4楼

I did the following in Eclipse with the Android Support Library ( APL ) project and the Main Project ( MP ): 我在Eclipse中使用Android支持库( APL )项目和主项目( MP )执行了以下操作:

  1. Ensured both APL and MP had the same minSdkVersion and targetSdkVersion . 确保APLMP具有相同的minSdkVersiontargetSdkVersion

  2. Added APL as a build dependency for MP : 添加了APL作为MP的构建依赖项:

    1. Going into "Properties > Java Build Path" of MP , and then 进入MP的 “属性> Java构建路径”,然后

    2. Selecting the "Projects" tab and adding APL . 选择“项目”选项卡并添加APL

  3. In the properties of MP , under "Android", added a reference to APL under library. MP的属性中,在“Android”下,在库下添加了对APL的引用。

1 and 2 got the references to Java classes working fine...however I still saw the error in the manifest.xml for MP when trying to reference @style/Theme.AppCompat.Light from APL . 1和2有到Java类的引用工作正常...但我还是看到了错误的manifest.xmlMP尝试引用时@style/Theme.AppCompat.LightAPL。 This only went away when I performed step 3. 当我执行第3步时,这只会消失。


#5楼

I will share my experience with this problem. 我将分享我对这个问题的经验。 I was going crazy because of this, but I found out that the problem was a bug with Eclipse itself, rather than my code: In eclipse, unable to reference an android library project in another android project 我因为这个而疯了,但我发现问题是Eclipse本身的一个错误,而不是我的代码: 在eclipse中,无法在另一个android项目中引用一个android库项目

So, if you have the Android Support Library in your C: drive and your project in the D: drive on your computer, Eclipse won't function correctly and won't know where the Android Support Library is (green tick turns into red cross). 因此,如果您的C:驱动器中有Android支持库,而您的项目位于计算机上的D:驱动器中,Eclipse将无法正常运行,并且无法知道Android支持库的位置(绿色勾号变为红叉)。 To solve this, you need to move both projects onto the same hard drive. 要解决此问题,您需要将两个项目移动到同一个硬盘驱动器上。


#6楼

Follow the steps of @rcdmk. 按照@rcdmk的步骤操作。 Delete the android support v4.jar in YOUR project. 删除您项目中的android支持v4.jar。 It conflicts with the new updated version found in appcompat. 它与appcompat中的新更新版本冲突。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值