问题
I need to implement the actionbar in Android 2.x I've tried with this post and setup the support library as mentioned in thisofficial article.
Here are the steps that I've followed for implement the ActionBar using the appcompat support library:
First, I create the project with the following configuration (I don't create an icon and a default activity):
Minimum Required SDK: API 10: Android 2.3.3 (Gingerbread)
Target SDK: API 19: Android 4.4
Compile with: API 10: Android 2.3.3 (Gingerbread)
Theme: None
After, in the Project properties => Android => Library I add the android-support-v7-appcompat library project.
After this, I get 128 errors like this in the project where I use the appcompat library. All of them are related with the Holo theme:
[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'.
Please, note that the error only occurs with the values-v14 and values-v11 folders in the appcompat library project. Here are 2 examples of the errors I get:
[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'.
Also, there are few error not related with the Holo theme:
[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'.
Has anyone had the same problem?
回答1:
Set "Compile with" to API Level 19 as well - when you compile your app with SDK level 10, the compiler doesn't know the elements shown in the error log.
回答2:
You need to reference the res directory from AppCompat to your project. There you can find all resource files, which are needed for the Support ActionBar.
How to add those resource files is described pretty good on the google developer site: http://developer.android.com/tools/support-library/setup.html
Scroll down to :"Adding libraries with resources". Follow the instructions and everything should be fine ;)
回答3:
As blackfizz said, http://developer.android.com/tools/support-library/setup.html should give you a good how-to on how to setup the library in Eclipse.
On another note though: I can highly recommend using Android Studio IDE, as it supports the gradle build system which will enormously help with your struggle with setting up the different libraries. If you're using gradle, all you have to do is add:
dependencies {
...
compile "com.android.support:appcompat-v7:18.0.+"
}
to your build.gradle file and gradle will do the rest for you. Other third party libraries can also be added super easily. They'll automatically be resolved through Maven Central.
I've switched over to Android Studio IDE with gradle a few weeks ago and I never want to miss it again.
回答4:
Right click -> Property -> Switch tab to Android -> Select project build target api level 16
Add android:targetSdkVersion="16" in manifest file.
Your manifest looks like this:
<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>
- Clean and build library project.
That's IT.
回答5:
Go to Manifest.xml file of your project. Then set android:minSdkVersion="11". It will solve your problem. Late reply but may be helpful for others.
来源:https://stackoverflow.com/questions/20432314/use-appcompat-library-for-actionbar-support