Java 使用AppCompat库支持ActionBar
我需要在Android2.x中实现actionbar,我已经用post尝试过了,并按照官方文章中提到的设置了支持库 以下是我使用appcompat支持库实现ActionBar所遵循的步骤: 首先,我使用以下配置创建项目(我不创建图标和默认活动): 所需的最低SDK:API 10:Android 2.3.3(姜饼)Java 使用AppCompat库支持ActionBar,java,android,android-actionbar,android-actionbar-compat,android-appcompat,Java,Android,Android Actionbar,Android Actionbar Compat,Android Appcompat,我需要在Android2.x中实现actionbar,我已经用post尝试过了,并按照官方文章中提到的设置了支持库 以下是我使用appcompat支持库实现ActionBar所遵循的步骤: 首先,我使用以下配置创建项目(我不创建图标和默认活动): 所需的最低SDK:API 10:Android 2.3.3(姜饼) 目标SDK:API 19:Android 4.4 编译时使用:API 10:Android 2.3.3(姜饼) 主题:无 之后,在项目属性中,我添加了Android-support-v
目标SDK:API 19:Android 4.4
编译时使用:API 10:Android 2.3.3(姜饼)
主题:无 之后,在项目属性中,我添加了Android-support-v7-appcompat库项目 在这之后,我在使用appcompat库的项目中得到了128个错误。所有这些都与全息主题有关:
[2013-12-06 13:24:24 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.
[2013-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:225: error: Error: No resource found that matches the given name: attr 'android:dividerPadding'.
[2013-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:224: error: Error: No resource found that matches the given name: attr 'android:showDividers'.
[2013-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\themes_base.xml:94: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
请注意,该错误仅发生在appcompat库项目中的values-v14和values-v11文件夹中。以下是我所遇到的两个错误示例:
[2013-12-06 13:24:24 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:100: error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Holo.Widget.ActionBar.Subtitle.Inverse'.
[2013-12-06 13:24:24 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v11\styles_base.xml:26: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ProgressBar.Horizontal'.
此外,还有一些错误与Holo主题无关:
[2013-12-06 13:24:24 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.
[2013-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:225: error: Error: No resource found that matches the given name: attr 'android:dividerPadding'.
[2013-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\styles_base.xml:224: error: Error: No resource found that matches the given name: attr 'android:showDividers'.
[2013-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\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-12-06 13:24:38 - UsingSupportActionBar] C:\dev\Java\android\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\appcompat\res\values-v14\themes_base.xml:94: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
有人遇到过同样的问题吗?您需要将AppCompat中的res目录引用到您的项目中。您可以在那里找到支持ActionBar所需的所有资源文件 如何添加这些资源文件在google开发者网站上有很好的描述: 向下滚动至:“添加包含资源的库”。 按照说明去做,一切都会好起来的;) 也将“Compile with”设置为API级别19-当您使用SDK级别10编译应用程序时,编译器不知道错误日志中显示的元素。正如blackfizz所说,应该为您提供如何在Eclipse中设置库的良好指导 另一方面:我强烈推荐使用Android Studio IDE,因为它支持gradle构建系统,这将极大地帮助您设置不同的库。 如果您使用的是gradle,则只需添加:
dependencies {
...
compile "com.android.support:appcompat-v7:18.0.+"
}
到build.gradle文件,gradle将为您完成其余的工作。还可以非常轻松地添加其他第三方库。它们将通过Maven Central自动解决
几周前,我和gradle一起切换到Android Studio IDE,我再也不想错过了
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.support.v7.appcompat">
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="16"/>
<application />
</manifest>
就这样 转到项目的Manifest.xml文件。然后设置android:minSdkVersion=“11”。
它会解决你的问题。迟回复,但可能对其他人有帮助。非常感谢,伙计!:D这节省了将近一周的工作……:$有很多教程,但它们没有解释这个简单的配置。希望这对其他人有帮助D