My supported OS versions are >= 2.2
Now i want to use some >= 4.0 views in my application, So whats the best way to load different layouts according to different os? say I want to use default time picker in android os < 4.0 and holo theme time picker in android >= 4.0
Is it possible? whats the best way?
See this article.
Basically you can define different layouts per API level (and many other qualifiers). In your case, you would have:
res/layout/my_layout.xml (with the "old" controls).
res/layout-v15/my_layout.xml (with the "new" controls).
A device with API level 15 (i.e. ICS) or greater will use the "new" layout, while those with a lower API level will use the other one.
To simplify your code (e.g. usage of findViewById()) make sure that corresponding views in both layouts have the same ids.
Related
as I saw that some new APIs were came in ICS which is not available in gingerbread ,but I want to use this in my app and I want my min sdk version also 2.3, how can I do this ?
Can I develop two different user interface for the two different version of android in the same app.
like we can develop UI for different screen sizes by using layout-sw600dp or whatever we want ?
Use the -vNN resource set qualifier. res/layout/ would be used by default; res/layout-v11/ would be used by API Level 11+ devices; res/layout-v14/ would be used by API Level 14+ devices; etc.
All I have a different layout files for different versions of android like layout-v13 , but I noticed that the files are the same for newer versions of android (API 11-16). Is there a way to group them together as something like layout-v11,12,13,14,15,16? Thanks for your time!
If what you're trying to do is show a different layout depending on which API version is available on the device, you want to use configuration qualifiers. The specifics for alternative resources are also documented.
The most basic way to do it is to create a layout folder for each API level you want to use, formatted as follows:
res/layout/layout.xml (Default)
res/layout-v4/layout.xml (Android 1.6 and higher)
res/layout-v11/layout.xml (Android 3.0 and higher)
From Android official documentation
In your case layout-v11 this will be used by devices running Android 3.0 Honeycomb and above
layout-v11 will be used by all devices running Android 3.0 and above. You should only break up the folders (i.e. layout-v11, layout-v12, etc.) if devices running the specific version require a different layout.
I have to program my Android app with the best compatibility to different screen sizes (tablets and smartphones) and to the versions 2.3, 3.2 and 4.0.
I know about the possibliy to name the folders of the layout like res/layout-sw600dp/. to match the layout exactly to different screen sizes.
So, cause I will use completely different layouts for Tablets / Smartphones, I would start with a "Load Screen", which tests which Android-version is used and if there is used a tablet-or smartphone-device, cause for example in the layout for the Tablet, there will be Buttons on some screens that won't be there on the smartphone.
So I will have to separate all this in packages, like this:
Common
2.3
Tablet
Smartphone
3.2
Tablet
Smartphone
4.0
Tablet
Smartphone
I would choose this separation, cause it's the best way, in my opinion, to be prepared for upcoming *updates*, if, let's say there should be added a Button in the ToolBar in Android 4.0.
Is this separation a good thing in your opinion or is this a complete overload?
Are there any other new features in 4.0 that I should be aware of?
You can also name your resource folders to indicate version number (like /res/layout-v11) or (/res/values-v13)
Regarding your question about separation - it really depends on your particular requirement. A common approach to this problem is a fall-back mechanism: You provide a few specific layouts (for example, an xlarge landscape v11 layout), and a few generic ones to fall back to.
Of course, this is an "idealistic" solution; and it doesn't always work that way. In other words, it is mighty difficult to practically implement an app that is compatible with so many versions of Android solely by providing alternative resources. Even if you use the compatibility libraries (which helps a bit in reducing version-specific code); you will still have to adapt your code based on the version at run-time.
You can find out the Android version looking at Build.VERSION.
The documentation recommends you check Build.VERSION.SDK_INT against the values in Build.VERSION_CODES.
And based on that version you can set your layouts in if else conditions
I'm working on a Tablet application.
What's the difference between this two res folders: layout-large-v11 and layout-xlarge?
The first option is from the IOSched app.
Are both valid for tablets? Which one is better for design tablets layouts?
Many thanks for the help.
v11 is there to help distinguish between large devices that are still running older versions of android. This distinguishing is necessary because there were some big changes at Android 3.0 (version 11 of the api), in terms of style. So the v11 allows you to say "Ok, if this is a newer version of android, use this newer style of layout, other wise use this older style".
Bottom line, you only need to use it if you want to provide two different layouts: one for versions of android that are pre-3.0, and one for versions that are post-3.0. v11 actually has nothing to do with the size of the screen itself, merely what version of android you're running on.
I'm working a personal project that's going to include a home-screen widget updated with information from a service - I'm developing using a Android 3.1 tablet (physical) as well as an Android 2.3 emulated phone.
For the Honeycomb version, I'd like to use the StackView, building up 3-4 pages which the user can swipe through, whereas this isn't supported on pre-Honeycomb devices, so is there an easy way to
have Honeycomb devices use a StackView but have Gingerbread/earlier use a TextView (I think this can be done by using res/layouts-v1{1,2,3,4}
Have the RemoteView detect which it is and clear/create the StackView items or set the text on the TextView
You can indicate different layout for pre and post Honeycomb by using the v11 qualifier in your layout names. You can also use the Build class to detect what Build version you're running on and then load the appropriate layout.