use ActionBarSherlock library, error after use she

2019-04-14 22:21发布

问题:

My own project is using Android 2.1 API 7.

To implement action bar, I use ActionBarSherlock library. I imported the sherlock library into my Eclipse as an existing project. For sherlock, the target platform is Android v3.2 API 13 .

Then, I added sherlock as a library project to my own project. Then, I notice there is no R.java file under gen/ folder in my own project, and I got error like following in eclipse console:

JakeWharton-ActionBarSherlock-436230d/library/res/values-v11/abs__styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo'.

JakeWharton-ActionBarSherlock-436230d/library/res/values-v11/abs__styles.xml:48: error: Error: No resource found that matches the given name: attr 'android:actionBarSize'.

JakeWharton-ActionBarSherlock-436230d/library/res/values-v11/abs__styles.xml:49: error: Error: No resource found that matches the given name: attr 'android:actionBarStyle'.

...

I thought it was probably because of the sherlock should use higher version API, so I tried to set target platform to 4.03 API 15 on sherlock project. But it does not help.

Anyone use sherlock has experienced the same error?? How can I solve this problem?

P.S. my own project manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="my.frag.test"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MyActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

回答1:

You have to set the build target to API13 on your own project.

The minimum API level your app works on is defined by android:minSdkVersion in your manifest, NOT the build target.

Setting the build target to API13 does NOT make the ActionBar available on 2.1 devices, and that is why you have ActionBarSherlock.



回答2:

Both your app and the library need to be compiled with Android 3.2 for proper support.

You can set your minSdkVersion in the manifest as low as '4', however, to still support back through Android 1.6. The targetSdkVersion also must be set to '11' or higher.

Take a look at the samples in the samples/ folder of the project for an idea of how this is done.