Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:actionBarStyle requires API level 11

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>
like image 381
Jitendra Avatar asked Mar 11 '13 12:03

Jitendra


4 Answers

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.

like image 103
InsanityOnABun Avatar answered Oct 20 '22 11:10

InsanityOnABun


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.

like image 20
hardartcore Avatar answered Oct 20 '22 11:10

hardartcore


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.

like image 7
Timothy T. Avatar answered Oct 20 '22 10:10

Timothy T.


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

like image 7
madlymad Avatar answered Oct 20 '22 10:10

madlymad