55

Platform:4.3

API Level:18

AndroidManifest.xml:

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

values-v14\styles.xml:

  <resources>

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
</style>

 <style name="CustomActionBarTheme"
       parent="@style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar"
       parent="@style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>
</style>

I am an android newbie.Thanks very much!

user441222
  • 2,001
  • 7
  • 27
  • 41
  • 4
    Change to '@android:style/Theme.Holo.Light.DarkActionBar' and '@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse' – hieuxit Aug 22 '13 at 02:43

7 Answers7

88

Do this:

"android:style/Theme.Holo.Light.DarkActionBar"

You missed the android keyword before style. This denotes that it is an inbuilt style for Android.

Steve
  • 9,270
  • 5
  • 47
  • 61
Sushil
  • 8,250
  • 3
  • 39
  • 71
  • 31
    Official documentation contains the error (no `android` prefix): https://developer.android.com/training/basics/actionbar/styling.html – Sébastien Nov 05 '13 at 10:12
  • The `Theme.Holo` is available only after API 11. Is there a way to make it available for app with minsdk as 8 ? Or is there an alternative similar AppCompat theme? – faizal Jul 11 '14 at 07:09
  • @Sebastien, They can't even get the tutorials right? – Pacerier Nov 20 '14 at 02:33
  • @faizal Try: `"@style/Theme.AppCompat.Light.DarkActionBar"` – see https://developer.android.com/training/basics/actionbar/styling.html#AndroidThemes – Nolan Amy Jun 22 '15 at 21:23
  • internal themes might not use "android:" prefix. Just be mindful if you are copying item to your own custom theme. – Logic1 Apr 22 '16 at 00:50
  • Thanks bro. The documentation is not strict. https://developer.android.com/about/versions/android-4.4.html – DysaniazzZ Aug 24 '16 at 13:06
14

Make sure you've set your target API (different from the target SDK) in the Project Properties (not the manifest) to be at least 4.0/API 14.

Harshal Benake
  • 2,391
  • 1
  • 23
  • 40
9

The @android did not work for me. When I use android (without the @) it works like a charm.

Example:

<style name="CustomActionBarTheme"
       parent="android:style/Theme.Holo.Light.DarkActionBar">
Bouke Nijhuis
  • 349
  • 2
  • 7
3

There is a major error in the tutorials destined for newbies here: http://developer.android.com/training/basics/actionbar/styling.html

It is major because it is almost impossible to detect cause of error for a newbie.

The error is that this tutorial explicitly states that the tutorial is valid for api level 11 (Android 3.0), while in reality this is only true for the theme Theme.Holo (without further extensions and variants)

But this tutorial uses the the theme Theme.holo.Light.DarkActionBar which is only a valid theme from api level 14 (Android 4.0) and above.

This is only one of many examples on errors found in these tutorials (which are great in other regards). Somebody should correct these errors this weekend because they are really costly and annoying timethieves. If there is a way I can send this info to the Android team, then please tell me and I will do it. Hopefully, however, they read Stackoverflow. (let me suggest: The Android team should consider to put someone newbie to try out all tutorials as a qualification that they are valid).

Another error I (and countless other people) have found is that the appcombat backward compliance module really is not working if you strictly follow the tutorials. Error unknown. I had to give up.

Regarding the error in this thread, here is a quote from the tutorial text with italics on the mismatch:

" For Android 3.0 and higher only

When supporting Android 3.0 and higher only, you can define the action bar's background like this:

    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme"
        parent="@style/Theme.Holo.Light.DarkActionBar"> 

ERROR1: Only Theme.Holo can be used with Android 3.0. Therefore, remove the "Light.DarkActionBar etc.

ERROR2: @style/Theme.Holo"> will not work. It is necessary to write @android:style/Theme.Holo">in order to indicate that it is a built in Theme that is being referenced. (A bit strange that "built in" is not the default, but needs to be stated?)

The compiler advice for error correction is to define api level 14 as minimum sdk. This is not optimal because it creates incompliance to Andreoid 3.0 (api level 11). Therefore, I use Theme.Holo only and this seems to work fine (a fresh finding, though).

I am using Netbeans with Android support. Works nicely.

carl
  • 501
  • 3
  • 10
  • That was interesting. How about the variants of `Theme.AppCompat`. Are they also to be used only on API 14 and above? For example, will `Theme.Appcompat.Light.ActionBar` work on API 8 ? – faizal Jul 11 '14 at 09:10
  • I was trapped into this once again, this time as I reversed from Theme.Holo to Theme.AppCompat because this is recommended for ChromeCast implementation. Forgetting then that I had added the "@Android:style\.." I did not revert to "@style\..." and was trapped for hours. See comment below on this. – carl May 18 '16 at 14:38
1

If you use android studio, this might be useful for you.

I had a similar problem and i solved it by changing the skd path from the default C:\Program Files (x86)\Android\android-studio\sdk to C:\Program Files (x86)\Android\android-sdk .

It seems the problem came from the compiler version (gradle sets it automatically to the highest one available in the sdk folder) which doesn't support this theme, and since android studio had only the api 7 in its sdk folder, it gave me this error.

For more information on how to change Android sdk path in Android Studio: Android Studio - How to Change Android SDK Path

Community
  • 1
  • 1
0

in addition,if you try to use CustomActionBarTheme,make sure there is

<application android:theme="@style/CustomActionBarTheme" ... />

in AndroidManifest.xml

not

<application android:theme="@android:style/CustomActionBarTheme" ... />
hsw117
  • 65
  • 5
0

You can change this one parent attribute ="android:style/Theme.Holo.Light.DarkActionBar"

suba
  • 69
  • 5