10

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

Klaasvaak
  • 5,634
  • 15
  • 45
  • 68

4 Answers4

11

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.

jgiles
  • 721
  • 8
  • 13
  • You are right. Every time editing the styles.xml triggers the error. When you clean the project (no build) the error is gone. When you build the project with the styles.xml closed the error is gone. So you can build it with a lower API level as well it just has to be closed. – Klaasvaak Mar 07 '13 at 11:06
  • @jgiles, are you using OSX? I'm experiencing the same problem running ADT v21.1.0-569685 on OSX. My co-worker on Windows sees no such errors on windows, running the exact same project. – nipponese Mar 11 '13 at 22:02
10

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").

Patrick
  • 4,720
  • 4
  • 41
  • 71
  • 5
    Ideal solution - thanks. Don't forget you also need to declare xmlns:tools="http://schemas.android.com/tools" in the xml. – greg7gkb Apr 10 '13 at 23:41
  • Ah thanks for the comment, greg7gkb. I tend to forget the namespaces, especially when Eclipse automagically inserts them ;) – Patrick Apr 11 '13 at 06:38
  • +1 for the note that Eclipse can insert this automatically via the Quick fix. – Natix Aug 23 '13 at 12:27
1

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).

Community
  • 1
  • 1
Booger
  • 18,579
  • 7
  • 55
  • 72
0

In Intellij IDEA (presumably also eclipse) you can suppress API warnings for the entire file by adding

<!--suppress AndroidLintNewApi -->

Before you declare the schema. So your xml file would then look something like this:

<!--suppress AndroidLintNewApi -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    < ... />
</resources>
JBirdVegas
  • 10,855
  • 2
  • 44
  • 50