Android 无法解析@style/Theme.Sherlock
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10352628/
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
Cannot Resolve @style/Theme.Sherlock
提问by Ten_Ten_Steve
I'm trying to make use of Actionbar Sherlock 4, targeting sdk 15 and min sdk 8. After following the directions provided on the Usage website and the great videos posted here: http://www.youtube.com/watch?v=avcp6eD_X2k
我正在尝试使用 Actionbar Sherlock 4,针对 sdk 15 和 min sdk 8。按照使用网站上提供的说明和此处发布的精彩视频进行操作:http: //www.youtube.com/watch?v= avcp6eD_X2k
I'm still encountering a problem. When I try to add android:theme="@style/Theme.Sherlock" to my manifest file , I get the error:
我仍然遇到问题。当我尝试将 android:theme="@style/Theme.Sherlock" 添加到我的清单文件时,出现错误:
No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock').
找不到与给定名称匹配的资源(在 'theme' 处,值为 '@style/Theme.Sherlock')。
I have included the actionbar Sherlock library project into my project, and the import statements are there and not coming up with any errors and I've
我已经将 actionbar Sherlock 库项目包含在我的项目中,并且导入语句在那里并且没有出现任何错误,我已经
extends SherlockActivity implements ActionBar.TabListener
扩展 SherlockActivity 实现 ActionBar.TabListener
just like in the Demo code and documentation Yet still, eclipse gives me this error. Any ideas out there?
就像在演示代码和文档中一样但是,eclipse 仍然给我这个错误。有什么想法吗?
采纳答案by t0mm13b
I encountered a strange anomaly that might help!
我遇到了一个可能有帮助的奇怪异常!
Have built android project that uses ABS, running it on Gingerbread works fine, in ICS it crashes, the crash under ICS occurs due to this, check your AndroidManifest.xml(have trimmed out bits for brevity...
已经构建了使用 ABS 的 android 项目,在 Gingerbread 上运行它可以正常工作,在 ICS 中它崩溃了,因此在 ICS 下发生崩溃,请检查您的AndroidManifest.xml(为了简洁起见,已删减了一些位...
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:theme="@style/Theme.Sherlock">
It was the android:themepart that caused the crash under ICS, it worked fine under Gingerbread and older versions!. Solution was to remove it completely! Then from your Activity, do this:
是android:theme部分导致了 ICS 下的崩溃,它在 Gingerbread 和旧版本下运行良好!。解决方案是将其完全删除!然后从您的活动中,执行以下操作:
@Override
public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
this.setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
}
super.onCreate(savedInstanceState);
... // MORE CODE ....
}
This fixed up the crash under ICS, the theme style is not liked by ICS, but it works fine for both versions less than 2.3 and 4.0 upwards.. weird error but that I discovered by fluke!
这修复了 ICS 下的崩溃,ICS 不喜欢主题样式,但它适用于低于 2.3 和 4.0 以上的两个版本......奇怪的错误,但我偶然发现了!
Remember to apply the theme before calling the base class's own onCreate!
记得在调用基类自己的onCreate之前应用主题!
回答by domsom
The pitfall I encountered was this: The reference to the ActionBarSherlock project needs to be in the Android->Libraries section of the project properties, while I had been adding it to the Build Path->Libraries.
我遇到的陷阱是:对 ActionBarSherlock 项目的引用需要在项目属性的 Android->Libraries 部分,而我一直将它添加到 Build Path->Libraries。
回答by dbyoung
My standard procedure for including a library project on Eclipse goes like this:
我在 Eclipse 上包含一个库项目的标准程序是这样的:
- Import library project
- Right click on library project Properties -> Android -> Set Project Build Target (insure library and primary project are the same)
- Right click on library project Android Tools -> Fix Project Properties
- Select the library project then Project -> Clean...
- Select primary project then Project -> Clean...
- 导入库项目
- 右键单击库项目属性 -> Android -> 设置项目构建目标(确保库和主项目相同)
- 右键单击库项目 Android 工具 -> 修复项目属性
- 选择库项目,然后选择 Project -> Clean...
- 选择主项目,然后选择 Project -> Clean...
That should fix whatever ails you.
那应该可以解决你的任何问题。
回答by German Tamayo
I finally find the solution:
我终于找到了解决方案:
- IMPORTANT! Copy the same android-support-v4.jar in both projects: in library and your project (this is the principal problem).
- Import "library" project TO YOUR WORKSPACE
- Right click on library project Properties -> Android -> Check "Target Name" 4.x (any, API level 14,15 or 16). Bottom check "Is library".
- In properties, go to "Java Build Path", tab "Libraries" And find "android-support-v4.jar" normally in "Android Dependencies". Ok and Close Properties.
- Right click on library project Android Tools -> Fix Project Properties
- in Menu Project -> Clean... and select to clean the "Library" Project.
- 重要的!在两个项目中复制相同的 android-support-v4.jar:在库和您的项目中(这是主要问题)。
- 将“库”项目导入您的工作区
- 右键单击库项目 Properties -> Android -> Check "Target Name" 4.x (any, API level 14,15 or 16)。底部检查“是图书馆”。
- 在属性中,转到“Java 构建路径”,选项卡“库”,然后在“Android 依赖项”中正常找到“android-support-v4.jar”。确定并关闭属性。
- 右键单击库项目 Android 工具 -> 修复项目属性
- 在菜单项目 -> 清理...并选择清理“库”项目。
In this place, your project "library" must to be done (without errors)
在这个地方,你的项目“库”必须完成(没有错误)
- Create or import your own project. Example "MyProject"
- In properties, go to "Java Build Path", tab "Libraries" And find "android-support-v4.jar" normally in "Android Dependencies".
- Now go to "Projects" Tab. Add... and select "library" project.
- Now in properties go to Android -> Check "Target Name" 4.x (any, API level 14,15 or 16). IMPORTANT: Must to be the same of "library" project. Bottom "Is Library" must to be UNCHECKED and in this place press Add... And select "library" project. Ok and Close properties.
- Right click on "MyProject" project Android Tools -> Fix Project Properties
- in Menu Project -> Clean... and select to clean the "MyProject" Project.
- 创建或导入您自己的项目。示例“我的项目”
- 在属性中,转到“Java 构建路径”,选项卡“库”,然后在“Android 依赖项”中正常找到“android-support-v4.jar”。
- 现在转到“项目”选项卡。添加...并选择“库”项目。
- 现在在属性中转到 Android -> 检查“目标名称”4.x(任何,API 级别 14,15 或 16)。重要提示:必须与“库”项目相同。底部的“是库”必须是未选中的,在这个地方按添加...并选择“库”项目。确定并关闭属性。
- 右键单击“MyProject”项目 Android 工具 -> 修复项目属性
- 在 Menu Project -> Clean... 并选择清理“MyProject”项目。
Already, your project must to be done. If the error persist, restart Eclipse.
您的项目必须已经完成。如果错误仍然存在,请重新启动 Eclipse。
回答by Houcheng
I resolved this issue by the follwoing 2 steps on my projects:
我通过以下两个步骤解决了这个问题:
- Remove the "library" from "project properties"/build path and add library in "project properties"/Android/Library
- Right Click on project "Android Tools" -> "Add support library"
- 从“项目属性”/构建路径中删除“库”并在“项目属性”/Android/Library 中添加库
- 右键单击项目“Android 工具”->“添加支持库”
回答by user3780468
after importing both projects i.e. library and settingActivity,first clean and build them. Then right click on settingActivity project->properties->select second option from left menu (i.e android). on right hand side their is library section just click on add library. prper path will automatically comes in that frame. Thats solve my problem,i got no errors.
导入两个项目后,即 library 和 settingActivity,首先清理并构建它们。然后右键单击settingActivity project->properties->从左侧菜单中选择第二个选项(即android)。在右侧他们的库部分只需单击添加库。prper 路径将自动出现在该框架中。那解决了我的问题,我没有错误。