Using different resource files depending of the SDK API level (using Eclipse)? - android

I am writing an Android app, targeting API levels 8 to 14. I want to use the Theme.Holo.Light theme for API level 11 and higher, and a Theme.Light theme for lower API levels.
The content of res/values/style.xml is:
<resources>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>
and the content of res/values-v11/style.xml is:
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light" />
</resources>
This compiles well for API level 14, but when setting my target API level to 8, it gives the following error: "Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo'" in res/values-v11/style.xml, and "Android AAPT Problem".
If I remove the file res/values-v11/style.xml, the app compiles correctly for API level 8 target.
Now, my understanding is that when compiling for API level 8 the build system should ignore anything inside a resource folder whose name ends with "-v11".
What am I doing wrong?

It's because API 8 got no clue what Theme.Holo.Light is as it was introduced in API11. You have to compile against highest API version you use elements of.
And you understand resource selectors wrong. It's is not used for build the app conditionally. It's used to pick up right resource at runtime.
See this article.

Related

Difference between styles.xml (res\values\styles.xml) and styles.xml (res\values-v21\styles.xml)?

What is the main difference between these two files : styles.xml (res\values\styles.xml) and styles.xml (res\values-v21\styles.xml ?
For targeting old android versions, which file should we modify?
Android will use res\values-v21\styles.xml if the user's device is running Android API level 21+ (Android 5.0+) & will use res\values\styles.xml for older versions
It just means that the styles differ in android versions.
styles.xml in values-v21 mean that, that particular style is for Android API 21 version 5.0+
while styles.xml will be for any other Android version besides 5.0+.
its the same as language where you create an activity for en, fr, pk etc.
Older version would automatically be targetted by the values/styles.xml file.

No resource found that matches the given name 'android:Theme.Holo.Light'

I have created a project with following settings for Target :
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
But following error persists at values-v11 and values-v14:
ERROR : No resource found that matches the given name 'android:Theme.Holo.Light'
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
Assuming you're using Eclipse, you need to right-click your project in the Package Explorer, select Properties, select Android, and set Project Build Target to API level 14 or higher. Or equivalently, set target=android-14 or higher in your project's project.properties file, but note that this file is autogenerated by Eclipse, so manually editing it is not recommended.
First there is problem in the parent attribute, you have to use parent="android:style/Theme.Holo.Light"
Second, Since Holo Theme was introduced in API level 14... so you have to change your android:minSdkVersion="8" to android:minSdkVersion="11", On newer versions it will automatically use Holo theme. You can further read about Holo Theme at
On Android Developers Blog
on Developers.Android.com
However if you want to support previous versions of Android for Holo Themes. You can use Holoeverywhere library.
TextAppearance.Holo.Widget.ActionBar.Title appears to have been added in API Level 13. Make sure your build target is set to 13, not just 11.
AndroidManifest.xml:
<uses-sdk
android:minSdkVersion=...
android:targetSdkVersion="11" />
you can Click Properties of this project and click Android,chose Target Name byond you aim project.

Android Styles and Values issue

My Android project was working fine when I noticed that I had checked SDK version 4.2 when I meant to target Google 2.33. I set the project back to G2.33 (In the manifest it minsdk = 8 targetsdk=11) and now I have errors on two different styles.xml files in two folders named Values-v11 and values-v14.
the styles.xml in the Values-v14 folder has an error on the following line...
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
the st yles.xml in the Values-v11 folder has an error on ...
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
My other projects, that all target 2.33 don't even have these folders. What is the best way of me getting out of this mess?
Thanks, Gary
You could simply delete these folders if you don't want anything specific for SDK level 11, and the one for 14 won't be used anyway if your targetsdk is 11.
If you want to retain the one for api level 11 for custom behaviour in API level 11, you need to set the project to compile with API level 11 - i.e. if in Eclipse, select the project, go to Properties, select Android and then set the project build target to "Android 3.0" or "Google APIs" for API level 11 if you need the Google APIs.

How to use "values-v11" folder with Xamarin.Android

The android doc here states that I can target Api Level 8+ devices and still specify that I want to use the Holo theme for devices that are API Level 11+. I should be able to do this using two themes.xml files :
One would go in /Resources/values for devices of API Level 8, 9 and 10
One would go in /Resources/values-v11 for devices with API Levels 11+
In a Xamarin.Android project, using Xamarin Studio it doesn't look like it's working, I get a compile time error :
Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.Holo'.
Am I doing something wrong here ? Is there a workaround ?
Theme.Holo is only available on API 11 and above.
If your project target is set to automatic, the system will build against the minimum level required (I think).
Try explicitly setting it to a higher API version.

#android:style/Theme_Holo resource not found

Being in Eclipse editing the AndroidManifest.xml the compiler shows me suggestion to add #android:style/Theme_Holo. But when compiling I get the message:
Error: No resource found that matches the given name (at 'theme' with value '#android:style/Theme_Holo')
Is there something wrong with my settings?
Introduced in Honeycomb.
android:theme="#android:style/Theme.Holo"
The holographic theme is new in Honeycomb (SDK level 11). If your project level is set below that, the theme won't be found. (Also note that the graphical layout editor can be set to a higher level than your project setting.)
Had the same error message showing up in the res/values-v11 and res/values-v14 folders of my Android project.
Solved it by setting the AndroidManifest.xml android:targetSdkVersion higher until it matched a version where the theme was available.
Example:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
Works fine for:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
Also might have to modify the target=<android:sdk-version> line within the project.properties text file.

Categories

Resources