android:actionBarStyle requires API level 11

AndroidAndroid ActionbarActionbarsherlock

Android Problem Overview


While using the ActionBarSherlock in xml at:

<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

I got this error:

android:actionBarStyle requires API level 11 (current min is 8) error

I'm using it for back porting my app with actionbar to 2.2 devices.

How to use them both together:

 <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
 <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

Android Solutions


Solution 1 - Android

Another option is to use the tools:targetApi attribute, which requires the tools namespace. This acts in a similar fashion to the @TargetApi annotation you can use in java files.

<resources xmlns:tools="http://schemas.android.com/tools">

<style name="MyThemes.MyTheme">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle" tools:targetApi="11">@style/Widget.Styled.ActionBar</item>
</style>

</resources>

Note the xmlns:tools="http://schemas.android.com/tools" in the <resources> tag, as it is required.

Solution 2 - Android

You have to use only :

<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item> 

as you can get the error, you have android:actionBarStyle available at API level 11.


If you want to be able to style your ActionBar to look the same in all API levels, you need to create different folders for the selected API level and create new style.xml/themes.xml files in these folders.

For example:

- res
  -- values
     -- styles.xml
     -- themes.xml // API LEVEL 8+
 -- values-v11
     -- styles.xml
     -- themes.xml // API LEVEL 11+
 -- values-v14
     -- styles.xml
     -- themes.xml // API LEVEL 14+

The second thing which I can think of is be careful which themes are you including to your current one at different API Levels.

For example, for API level 8: you will use @style/Theme.Sherlock.Light.DarkActionBar and you will have to use only actionBarStyle. While styling the action bar for API level 14+, you won't need actionBarStyle , because you probably will set Holo.Light theme as parent for your current one, so in this situation you will have to use android:actionBarStyle.

Solution 3 - Android

You can just select errors in Eclipse and press on your key "Delete". Then just run the project and it will work.

You have delete theses errors each time you modify your XML.

Solution 4 - Android

It depends what SDK Version you want to target:

Target devises lower than 11:

At your AndroidManifest.xml use:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="x" android:maxSdkVersion="10"/>

x anything between 8-10 (depends on your code)

At your style use:

<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>

Target any device:

At your AndroidManifest.xml use:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />

16 used at ActionBarSherlock example can be any greater or equal to 11 (depends on your code)

At your style use both:

<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item> 
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>

the 1st one is for ActionBarSherlock theme and the 2nd is for using the same theme in android devices that already support ActionBar

Edit: To clear Lint warnings (red underlining in XML file that may show up):

Clear Lint Warnings

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJitendraView Question on Stackoverflow
Solution 1 - AndroidInsanityOnABunView Answer on Stackoverflow
Solution 2 - AndroidhardartcoreView Answer on Stackoverflow
Solution 3 - AndroidTimothy T.View Answer on Stackoverflow
Solution 4 - AndroidmadlymadView Answer on Stackoverflow