Using support classes in new versions of Android - android

If I'm trying to make my App work on older devices, I use the Support Libary and ActionBarSherlock.
Of Course, they also work on newer devices. But should i use them on new OS versions, or change the code and resource files so that 4.0 devices for example all use the stock classes and not the support ones.
For example (pseudocode):
if (running 4.0+){
ActionBar= getActionBar();
}else{
ActionBar= getSupportActionBar();
}
or just use this one on all versions:
ActionBar= getSupportActionBar();
What are best pratices, and does that affect stability and perfomance ?

You answered yourself already: "Of Course, they also work on newer devices". If it works then it works. Compatibility lib is just portion of Android framework separated from Honeycomb+ code and offered as .jar for use on older devices. If you target older devices, with pre 3.x Androids and HC+ devices at the same time, then if you still want to use fragments and stuff you got no other choice anyway. And you also need compatibility library for ActionBarSherlock, as it needs it as well.

As far as I know, ActionSherlockBar itself automatically switches everything based on the OS version. So you don't need to bother.
I have used it in my application and it works pretty much the same both on 2.3.7 and 4.0.
This is from its website:
The library will automatically use the native action bar when appropriate or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.

Related

ActionBar from Support Library and phone above Android 3.0

I understand that for Android below 3.0 i need to use ActionBar from v7 support lib
My question is how v7 ActionBar behaves on phones above Android 3.0. Does is use native ActionBar or v7 ActionBar?
I am asking if v7 ActionBar on phones with Android 3.0 and above will be of less quality
(may be less features) than regular ActionBar
Thanks
If you decide to use ActionBarCompat - all your devices will get action bar from compat library. Of course you can have some really tricky API version checks and choose one over another in runtime, but efforts and code complexity just don't worth it. I wouldn't say it is going to be "less quality" since Google guys are really trying hard to make it look the same. Also Im pretty sure list of interfaces is exactly the same as native implementation.
From another hand, there is obviously a risk to hit some nasty bug which is not present (or already fixed) in native implementation, so it is all up to you to take this risk to the benefit of supporting older platforms.

Android TabHost deprecated

I am creating application which will support Android 2.2 to Android 4.1. The TabHost is deprecated in Android version 3.2. But the created application supported in all the versions. But I want to create the Tab bar application which will look like a tab bar in Android 4.1 while running the application in Android 4.2, If I am running the application in below android 3.2 version device, it must look like the tab bar in that device. How can I do this.?
There are many points to your question,
TabHost is not deprecated yet. Recently Google deprecated TabActivity and ActivityGroup.
Even if it deprecated, it doesn't mean it can't be used. If X is deprecated, it only means a better alternative named Y is there.
Now to answer your question, You have more than one options
You can use ActionBarSherlock as other answers suggests. (EDIT : ActionBarSherlock is now deprecated.)
You can use TabHost with fragments, See my answer here for a
good example. To use Fragment in pre 3.0 API's you need to use
Google's support library.
Try out ActionBarSherlock.
ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.
The library will automatically use the native action bar when appropriate or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android from 2.x and up.
Tutorials:
tutorial 1 , tutorial 2 ,
tutorial 3
Just to add, Android has introduced ActionBarCompat to ensure ActionBar is compatible with OS below 3.0 down to 2.1. You can use ActionBarCompat in the support library instead of ActionBarSherlock
http://android-developers.blogspot.co.uk/2013/08/actionbarcompat-and-io-2013-app-source.html

Android 4.0 Design Guidelines and Backwards Compatibility

Google has a great resource for Android 4.0+ Design Guidelines. But there is still a large percentage of Android users running 2.3.x.
What is the easiest way to use the latest design guidelines while still maintaining backwards compatibility with older OS versions? There are a lot of special menus and navigation tools in the guidelines that are probably Android 4.0+ only. Do they gracefully fall back to basic elements for older versions of the OS? Do you have to create a whole separate view/template for each major Android version?
What is the best approach to adopting the newest guidelines with leaving a large percentage of users out in the cold?
Use ActionBarSherlock and the HoloEverywhere libraries, as well as the Android Support libraries.
There is a support library from google (link) that ports back many of the Android 4 UI Features. You may look at the feature list on their homepage for details.
Furthermore, there is Actionbar Sherlock by Jake Wharton. This a is an extension to the Compatibility Actionbar that offers more features than the original from google. (link)
"Do you have to create a whole separate view/template for each major Android version?"
The answer for this is No, All you need is a single apk for all the Android versions,
But the UI would be changed depending on the OS version and screen size.
Android provides a number of support libraries for doing this.
The latest design guidelines are compatible only for Android 3.X (Honeycomb) and higher.
For the earlier versions, the UI would behave accordingly.
Please go through Android documentation about support libraries, and there you can find some samples too.
But if you want the same look for all the versions of Android, then you have to go for third party libraries like Actionbar Sherlock.

use holo theme on Android < 4.0

I'm developing an app for Android 2.2 and higher.
I use the great ActionBarSherlock (thank you, Jake Wharton !!) to use the action bar on pre-ICS devices.
While the actionbar looks great, all other gui elements have the look of the default theme of the device (in my case HTC Sense 3).
Is there a possibility to style my (>= Android 2.2) app on all android devices with the Holo.Dark.Theme?
I compile my app with Android 4.0.3, the minSDK version is 8.
Enjoy HoloEverywhere, that's the whole purpose of the project!
(Edit) new adress: https://github.com/Prototik/HoloEverywhere
No. That would require a back port of the complete Holo theme and styling, which Google chose not to do. It would also be a rather ambitious undertaking and I would think it is out of scope of the ActionBarSherlock project, whose focus is on ActionBar compatibility.
The best you can do is cherry pick the resources you most want from the ICS source and create your own custom theme/styles.

Implementing recently introduced Android design and UI guidelines on 2.x versions

Considering Android Design Guidelines announcement what is the best way to make apps which are compliant with them on Android 2.x phones? E.g. what is the best way to implement the ActionBar pattern?
ActionbarSherlock is a starting point. It includes the compatibility libraries from Google and comes provided as a project rather than JAR offering greater flexibility, should you need to alter anything. Version 4 is on the way which will also include ICS stuff.
As far as I am aware I believe ABS is backward compatible to 1.6, and makes use of the minSdkVersion and targetSdkVersion. It uses an extended version of the holo theme to create a light and dark version that includes the extra ActionBar goodness, which in turn you can extend to style your app.
I recorded a tutorial on YouTube to get people started.
I think it's better to use the compatibilty libraries directly, instead of another library based on those. Additionally, refer to the Google I/O App as stated at the bottom of the first link I gave. You can find the best practices about implementing a UI for several devices with compatibility libraries.
I found ActionBarSherlock to be pretty good. It will emulate ActionBar on older devices and use the native one on modern ones. It's an extension to Android compatibility library - so you will also get fragments and other ICS stuff.

Categories

Resources