The application currently has tabulations and bar custom made (by previous guy) from fragments to copy cat Apple design.
I want to move toward Android action bar to provide Android experience and usual behavior.
Should I implement Action Bar Sherlock or Action Bar Compat?
Pro ABS:
Lots of documentation
Action bar Tabs is well known (that's what I need to do)
About Holo theme? ABS is great to support it, how perform ABCompat?
Pro ABCompat:
Supported by Google (better in the long run?)
Better connection with navigation drawer (but I will not use one)
No external dependencies in Java Build path
What others arguments help decide? Which one should I pick ?
From my point of view, provided I succeed to do a action bar with fixed tabs, the Action Bar compatibility is the best choice (but not by much).
Thank you for helping me! (even providing arguments I missed)
The main reason that made me switch to ActionBarCompat is the Menu appearence in devices with android <= 2.3. With ActionBarSherlock, the menu appears very ugly, with the default menu of the device. With the ActionBarCompat, the menu appears the same way it appears when you open it in devices with Android >= 4.0 and hardware menu key.
But, be aware that the ActionBarCompat has some bugs to be resolved yet. I'm dealing with this bug:
SearchView taking all the space in the new ActionBarCompat
UPDATE:
Another bug:
https://code.google.com/p/android/issues/detail?id=58321&thanks=58321&ts=1375277660
UPDATE:
I've created a patched version of the ActionBarCompat to solve the issue with the ActionMode. See here:
The ActionMode is being created twice with the ActionBarCompat r18
The reasons why I migrated my app from ABS to Action Bar Compat were as follows:
I have only a very basic implementation of action bar tabs and I could see it would be simple to migrate
I prefer the Google documentation - it is clearer and more complete
Software maintenance will be simpler and less error prone because I now have no external dependencies.
I had run into a problem with ABS whereby I wanted to handle an orientation change (but you can't because of the way ABS hooks in to Android).
I haven't seen any statements from anybody connected with ABS about their long term plans for ABS. So I'm not convinced they are going to continue to support it. I may be wrong - but I haven't seen anything.
Performance is not really an issue for me, but I can't see why Google's "native" implementation would run slower than ABS and I suspect that it may perform better.
These are just my personal impressions.
I think that ActionBarSherlock was a brilliant piece of work, and a great service to Android developers. (By the way I don't have shares in Jake Wharton its developer.) Google have paid it the best compliment possible by including something that does essentially the same thing in essentially the same way (as far as I can tell) in the v7 support library.
But now that the functionality is officially supported some standard arguments apply as to which to choose.
ActionBarSherlock is a third party dependency, which represents a risk in terms of ongoing support. Unless it does something you really need that is not done by ActionBarCompat, or the latter has a bug which you can't work around or wait for a fix for, there's very little argument in favour of sticking with the former.
I recently migrated from ActionBarSherlock to ActionBarCompat and found only one or two minor issues, the main one being that a minor adjustment was required to the stock 9-patch images used for the action bar tab indicator backgrounds, in order to produce the standard tab behaviour on earlier android versions, in my case 2.2==API level 8==Froyo. (Specifically I adjusted the vertical stretchable regions so that they were not adjacent either to the top edge or the colored indicator bar at the bottom of the image.)
Related
I'm newbie in development for Android platform and trying to understand how do I know or predict when I have to use support classes? This is probably stupid question, but let me give you a simple example. Let's say I want to add a sharing functionality to my application so I go to DAC and see there an example of how this can be done. I read the manual carefully and see the note about limitations i.e.
Note: ShareActionProvider is available starting with API Level 14 and higher
It seems this is OK for me since the minSdkVersion is set to 14 in my app. I copy-paste that snippet to my project, launch the application and... it crashes with the following error:
05-21 12:42:07.638: E/AndroidRuntime(25291): java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.getActionProvider()
I update my sources to use the following code instead the one which I found in documentation:
MenuItem menuItem = menu.findItem(R.id.action_share);
ShareActionProvider mShareActionProvider = (ShareActionProvider)MenuItemCompat.getActionProvider(menuItem);
Starting app. At first sight it's working but instead of share icon I can see text SHARE in the ActionBar. Humm, after googling around I replace the following line in menu layout
android:actionProviderClass="android.widget.ShareActionProvider"
to
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
Hooray! Finally I've got what I want!
This is not the first time I experience such obstacles while learning the Android platform so I'm trying to find whether there is any rule of thumb which will help me to predict such situations?
As for support library, not that I've added it for purpose. This library was added automatically when I created project in Android Studio. After playing a little bit with Android Studio I've figured out that it automatically adds it to the project unless the min SDK is set to latest 21 or 22 versions. So technically almost all applications have to use this library to be run on wider range of Android devices. If this is true then why Android training and guide materials don't use support classes in examples?
Any help and advice will be highly appreciated.
I'm trying to find whether there is any rule of thumb which will help me to predict such situations
I have no idea what "such situations" are beyond the one that you have cited here.
In this specific case, the menu resource cited in the first step uses android:showAsAction="ifRoom" instead of something like app:showAsAction="ifRoom". The latter is required if you are using the appcompat-v7 action bar backport. Hence, this sample must not be using the appcompat-v7 action bar backport.
There is little question that the documentation could be improved in this area, to either provide instructions for both action bar implementations, or to at least positively state which action bar implementation that they are using.
So technically almost all applications have to use this library to be ran on wider range of Android devices.
No. Zero applications have to use appcompat-v7 to be run on a wide range of Android devices, going all the way back to API Level 1.
However:
If you want an action bar on devices running Android 1.x/2.x, you need an action bar backport, and appcompat-v7 is the only currently maintained full-featured backport that I am aware of (given that ActionBarSherlock is deprecated)
If you want to try to have a UI that resembles Material Design on devices running Android 4.4 and below, current editions of appcompat-v7 do that as well
I was using ActionBarSherlock to make my app run with app version of android and use actionbar, but now I don't need to support the old version and it is enough for me to support 4 and above , is there any benefit of ActionBarSherlock still for my case ?
Not really. Feel free to use the native API Level 11+ implementation of the action bar.
Note, though, that some things in Android may steer you in the direction of using an action bar backport... though the appcompat one published by Google, not ActionBarSherlock. For example, the recommended version of MediaRouteActionButton requires the appcompat action bar, though I am maintaining a port that works with the regular action bar.
So I have a few questions about implementing the Android action bar. Up to this point I haven't really made any apps that were (in my opinion) good enough to put on the market. This really seems to be my inability to understand how the layouts and action bar will work in different versions of Android.
Of course Google seems to be the best bet for this, but I come across a few grey areas that maybe someone can clear up. I can see that the Action bar was implemented in API level 11, but then what happens when I try to run it on a device lower than 3.0? Also, this seems to be the most helpful when understanding on how and where to use the Action bar, but does this mean the action bar is done all programatically and not in the layout? I guess it's safe to say that I'm a bit "intimidated" by using the action bar because of the different layouts I'll get in different devices... so is there a way to make it "look" like I have an action bar even though it's done purely through layouts? Or is that a bad habit to get into?
I have heard that maybe the compatibility library might work well, but I don't really know what it does and I'm not yet savy enough to understand the android documentation on what it "really" does. If it really is "that" helpful at supporting older devices, why isn't it built/come standard in the SDK?
I know this is a very broad question, but when it boils down to it, I just want to know if there really is a way to make all of my layouts look and work the same, or if it's even worth my time and just have the action bar auto downgrade for old devices.
Just an additional question, I have a Galaxy Nexus and all of the core Google Apps look awesome with the action bar, but is there a way to see these updated apps running on API 11 or lower?
Lastly, if anyone has stumbled upon a great tutorial on any of this please list it. I'm really trying to become knowledgeable on how Android layouts work in all API levels.
I can see that the Action bar was implemented in API level 11, but then what happens when I try to run it on a device lower than 3.0?
By default, the user will get options menus, as before. Or, use ActionBarSherlock to have an action bar working back to Android 2.1, as Mr. Weening noted.
but does this mean the action bar is done all programatically and not in the layout?
It is the same as options menus, using mostly menu resources and Java code.
If it really is "that" helpful at supporting older devices, why isn't it built/come standard in the SDK?
You are welcome to create a time machine and go back in time to add that code to Android devices dating back to 2009. You might be able to find a lightly-used flux capacitor on eBay, though tracking down a Mr. Fusion unit may be somewhat more troublesome. Or, if you're in the UK, see if you can find a used TARDIS dealer.
The rest of us, in the meantime, will use the Android Support package in part for its backports of fragments, GridLayout, etc., so we can use new capabilities that are not native to older devices, while maintaining API fidelity with the native implementations on newer devices.
To support older version of android with a same looking action bar you could take a look at Action Bar Sherlock
http://actionbarsherlock.com/
From their 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
This works fairly well.
If you're a little more adventurous and you'd want more control over it's layout, look and feel, you could always try to implement it yourself. It's not an easy task but the action bar is more of a ux design than an actual component. The code for the compatibility libraries is a good place to start then.
The easy way if you just need a menu, a title and an icon up there:
choose a Theme with ActionBar, e.g. 'Theme.Holo'
create a new menu i.e. actionbar.xml
Implement this in your Activity
#Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbar, menu);
return true;
}
Since this is roughly the same as a menu in older versions, the older versions just lack the ActionBar and have the old menu instead.
Or
If you want the same ActionBar in all your Versions including before API 11, as Geert already suggested:
http://actionbarsherlock.com/
If you try to use the ActionBar on a version of Android that is not supported then it will just crash your application. To get around this, you can implement the library ActionBarSherlock which uses the native ActionBar if available, otherwise it creates its own that has the same functionality. You can also check the Android version during runtime and handle it yourself. I would check this link out as it actually has an ActionBar example:
http://developer.android.com/training/basics/supporting-devices/platforms.html#version-codes
I'm writing an Android App and I'm trying to choose which compatibility library to choose to implement the ActionBar functionality.
I'm trying to choose between two libraries:
GreenDroid : https://github.com/cyrilmottier/GreenDroid
Android-Actionbar: https://github.com/johannilsson/android-actionbar
From what I could gather, AA(Android-Actionbar) seems to be simpler, and easier to style. But GreenDroid has additional features which make it the more powerful solution in general(not just for an Actionbar).
I left out ActionBarSherlock because it also supports fragments, is more complicated.
IF there are others that I missed, please share!
Use ActionBarSherlock.
It is based on ICS code, is actively developed, and will use the native actionbar when run on ICS. It also plays nicely with the compatibility library and will let your use ICS features such as the split action bar and share providers. Probably the biggest plus is that it uses exactly the same API as ICS. If you don't need fragmetns, you certainly don't have to use them.
Green Droid offers a custom look and feel, not exactly consistent with Android UI design guide lines. Android-Actiobnar is based on custom layouts and only offers basic features.
Here's a discussion (might be biased, since it's by the ABS author): http://corner.squareup.com/2012/05/actionbarsherlock-as-a-base.html
The Android-Actionbar is better, for sure.
Couldn't think of any other ones but I am sure there are.
I'm looking to create a cross-version compatible android tabbed layout.
The problem I'm running into is when implementing Google's example of TabActivity, I get a depreciation notice. The app I'm writing needs to be compatible down to 2.1, and I'm not finding a clear cut way to make it compatible.
I am aware of the versioning by folder (/layout-v4, /layout-v14, etc) but if possible I want to avoid this.
Are fragments the answer here and if so, does the Android Compatibility Layer V4 become the key to solving this problem?
I'd suggest the best approach might be to use the excellent (and free) ActionBarSherlock, so you can add Android 3+ action bar (including tabs) to apps going all the way back to v2.x versions.
I've used it on a few apps and it's pretty easy. I think it's the right approach to use the proper Action Bar interface across platform versions, and they include tabs and replace the whole TabActivity thing, which was pretty horrible anyway.
http://actionbarsherlock.com/