In my android app, we need to support everything from Gingerbread to Jelly Bean. In my stylesheets, I need to have 2 versions of some fields, for example:
<item name="popupMenuStyle">#style/PopupMenu.MyTheme</item>
<item name="android:popupMenuStyle">#style/PopupMenu.MyTheme</item>
The issue is that with a minSdkVersion of 8, the "android:" version of the fields don't compile, but without them, the styles don't get applied in the later OS's.
Is there a switch I have to check for in the XML file?
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
Compile your code against targetSdkVersion(api 17), It will solve the problem.
Update
you can create folders in /res like values, values-v11, values-v14, there you can add themes related to different api levels. On device < API 11, theme will be selected from 'values', similarly devices gaving api 11 or above will get theme from 'values-v11' etc
Related
If the minSdkVersion of my project is 11 then what is the api level of my project? I mean how
to check whether I am working in api version 2, 3 or above? thanks.
You can actually keep the project's targetSDK at the same level, and just use a minSDK value.
What this means is that your application will target to build against a certain API, but it will let phones with lesser versions of Android than that API to also run the app. The catch is that you have to make sure you don't make any API calls that don't exist in the older versions of Android.
To change this, go to your AndroidManifest.xml and add the following inside of the xml node:
<uses-sdk android:minSdkVersion="3" />
This would set your minsdk to Android 1.5. Change it 4 for Android 1.6 and so on.
But if you really want to change the TargetSDK, right click on your project --> properties. Then click the Android tab on the left. Then check the box of the target API you want to build against.
List of api level is here and example is here
The minSdkVersion attribute only specifies the lowest API level on which your application will run.
If you did not set targetSdk or maxSdkVersion, then your app will run on the api level of the android device (if it is above or equal of minSdkVersion).
See http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
1) Right Click On Project
2) Click on "Properties"
3) Select "Android" from left Tab
Check targetSdkVersion in AndroidManifest.xml.
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
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.
I have defined a theme in values/themes.xml:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light.NoActionBar">
</style>
</resources>
and in my AndroidManifest.xml I have:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
The code is compiled and I see the proper result, but IDE tells me it cannot resolve symbol #android:style/Theme.Holo.Light.NoActionBar. Please advice why.
I have the same problem, try to change the android compiling libraries to the 3.2 Android version. It will let you use this themes and should be compatible with previous versions.
Be careful with the API you use. Despite of this you can set your minSdkVersion to 8.
Your minSdkVersion is too low for the Holo theme. The Holo theme is only available on SDK 11 (Honeycomb) and later. You may want to look at ActionBarSherlock. Since it looks like you're not using the action bar, you could also put separate themes.xml files in values and values-v11.
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.
It appears the best way to develop an Android application today is to target android-17 in project.properties along with minSdkVersion "whateversuitsyou" and targetSdkVersion 17 in the manifest.
In this configuration, the standard lint checks will notify about any API calls which are only available in API versions above "whateversuitsyou" and one can use reflection etc to dynamically support the newer features, if any.
However, in this setup, at least without further configuration, it is possible to have style and theme attributes in XML not placed in the appropriate folder, like referring to "Holo" elements in the default resource folder when "whateversuitsyou" is smaller than 11 aka Honeycomb.
It seems apps will not crash if they encounter unknown XML style attributes. LogCat will show an error, like "Style contains key with bad entry".
Not sure whether the whole style is checked upon app startup; if so, it is certainly possible to run the app once on every API version to check for any problems. However, that's not exactly desirable. Besides, styles and themes are not the only version specific resources.
Is there a way to make lint check the resources in general against minSdkVersion and API versio XY for folder *-vXY? Can someone shed some light on this?
Luckily, with the current (updated) configuration, this has become a non-issue, because the development framework handles the situation just the way it should.
Example:
project.properties:
target=android-11
AndroidManifest.xml:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
You can now use API 8 XML style and theme attributes everywhere and API 11 XML style and theme attributes in -v11 subfolders.
Works with Eclipse Juno Service Release 1, Android SDK Tools 21.1 and Android SDK Platform-tools 16.0.1.