我需要为 2.3 及更高版本的设备添加操作栏。
我最近知道了 appcompat v7 支持库,它正是这样做的。
我已经按照支持库设置指南 http://developer.android.com/tools/support-library/setup.html,一步一步,清理,构建,再次清理,重新启动eclipse,将SDK和插件升级到最新版本(只是为了意识到SDK 构建工具 v19 已损坏 https://stackoverflow.com/questions/19727915/android-dex-gives-a-bufferoverflowexception,所以我不得不删除它们)。两个小时后我仍然无法构建我的项目。我收到这些错误:
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v11\themes_base.xml:33: error: Error: No resource found that matches the given name: attr 'android:windowActionBar'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v11\themes_base.xml:42: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v11\themes_base.xml:44: error: Error: No resource found that matches the given name: attr 'android:windowActionBar'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:31: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:41: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:57: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:67: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:83: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light.DarkActionBar'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:94: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
我已经尝试了以下问题中的所有内容,但无济于事:
向 Android 项目添加支持库 https://stackoverflow.com/questions/18293088/adding-support-libraries-to-android-project
设置 android-support-v7-appcompat R.java 后丢失 https://stackoverflow.com/questions/18563441/after-setting-up-android-support-v7-appcompat-r-java-is-missing
Android 支持库 v7:检索项目的父级时出错 https://stackoverflow.com/questions/18964902/android-support-library-v7-error-retrieving-parent-for-item
无法找到新的 Android ActionBar 支持的 Theme.AppCompat.Light https://stackoverflow.com/questions/17870881/cant-find-theme-appcompat-light-for-new-android-actionbar-support
在 Eclipse 中添加库 v7 AppCompat 时如何解决错误“未找到与给定名称匹配的资源”? https://stackoverflow.com/questions/18429951/how-to-resolve-the-error-no-resource-found-that-matches-the-given-name-when-ad
我并不是说这些答案无效,只是因为某种原因它们对我不起作用(我认为这是因为谷歌讨厌我)。
这是我的目标 sdk 的清单行:
对于图书馆:
<uses-sdk android:minSdkVersion="7"/>
对于主要项目:
<uses-sdk android:targetSdkVersion="19" android:minSdkVersion="8"/>
尝试了所有可能的组合、每次更改后的清理和构建,但仍然没有运气。
看起来这是一个与 Holo 有关的问题。我真的根本不需要Holo,只需要ActionBar。现在我只是切换到 ActionBarSherlock,它过去对我来说效果很好。但我真的很想知道我做错了什么,为什么有些东西不起作用,尽管我花了相当多的时间研究这个问题。为什么集成一个应该开箱即用的库会如此痛苦。
是否可以通过支持 v7 库仅获取操作栏?