Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theming ActionBarSherlock gives api level error

I updated my project from Android 4.2 to Android 4.2.2 and I suddenly get this error in my styles.xml:

<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
   <!-- Requires level 11. Current: 7 --> <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

How do I fix this? According to the ABS docs this is how it should be done. See: http://actionbarsherlock.com/theming.html

like image 655
Klaasvaak Avatar asked Mar 05 '13 10:03

Klaasvaak


3 Answers

I tried restarting, but I ultimately needed to clean the project: Click "Project->Clean..."

The error came back every time I saved my styles.xml. For now, I am setting my minimum API level to 11 temporarily while editing that file to avoid the errors, and then resetting it back down and cleaning when I want to run it on my low-API-level emulator.

Edit: If you don't like leaving your min SDK version artificially high, it also works for me to change it to 14 (some other high number), save AndroidManifest.xml, change it right back, and save again.

like image 147
jgiles Avatar answered Sep 29 '22 02:09

jgiles


I used the suggested quick fix of Eclipse (CTRL-1 on the underlined element) and just added the warning suppression tools:ignore="NewApi"

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

This way you don't have to ignore the whole Lint warning, which might be handy in other cases, and you can compile the project without having to readjust the target API every time you edit the file.

Update: As greg7gkb pointed out in the comments: Don't forget the namespace declaration (xmlns:tools="schemas.android.com/tools").

like image 28
Patrick Avatar answered Sep 29 '22 03:09

Patrick


Ultimately, you really should add the attribute that is giving you the error in an API specific styles.xml file.

This SO answer describes this much better than I could: android:actionBarStyle requires API level 11

I think ALL the other answers are not fixes, but work-arounds (subverting the error, but ultimately not fixing it).

like image 30
Booger Avatar answered Sep 29 '22 01:09

Booger