Yet another compatibility problem from me.
BACKGROUND
I have an application that works in all API's now that I downloaded a custom google maps compatibility support library which is an extension of the Compatibility Support Library and allows me the have fragments along with maps in API levels < 3.0. It does this by making me extend my activity by FragmentActivity, which due to this custom library is also a subclass of MapActivity.
THE PROBLEM
I also need to implement a tabbed Action Bar throughout my application on different API levels. It's possible to do this using ActionBarSherlock. However, that also involves downloading and extending my Activity`` byFragmentActivity` using this custom library and thats a problem as I then lose the ability to have maps because I can't extend using both libraries versions?
THE QUESTION
How can I have both features in my application?
If this isn't the way to do it, how can I do it?
Thanks in advance.
UPDATE
So I have implemented a system where I can display the action bar in api's greater than 3.0 and not display if they aren't.
Here is the code.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.show();
} else {
//Do something else
}
POSSIBLE SOLUTION
Would the best way to go about it be to create a custom ActionBar Module that is just a group of views with some functions to make it act and look like an action bar?
Do you try to extend your FragmentActivity by SherlockActivity ?
So here is the solution that I came up with.
ActionBarSherlock wasn't an option for me due to the fact I was already using a version of the compatability library that allowed me to use GoogleMaps along with Fragments and if I used the ActionBarSherlock library I would have lost this functionality.
My Solution
I decided to implement my own custom ActionBar which is a combination of Views and TextViews.
I have one class extending Fragment (the android support version) called CCActionBar and this inflates three custom objects called CCTab which extend TextView. These three tabs (as it says in the name) are acting as my tabs so we override when they get touched, pass them to our CCActionBar which may then pass it onto our MainActivity to handle any navigation.
To detect if we need to create this Custom Action Bar due to API level I use the following code.
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
//setup a normal action bar because the api level supports it
} else {
//setup our custom action bar
}
So that's my solution, it may not be the correct one but it works for me.
Any questions please ask.
Related
I am developing an android app, where I want to put action bar for phones below API 11.
I am following the below link.
http://hmkcode.com/add-actionbar-to-android-2-3-x/
I am making use of the v7 support library, and I am able to get the actionbar. But, the problem is I want to add a navigational listener or tab listener to the action bar. How is it possible.
Please help! Thanks in Advance.
You should use ActionBarSherlock. It is an excellent library of tools that allow you to use Action Bars in older phones and is widely used. The catch is that all your Activities will need to extend SherlockActivity instead of Activity and you have to be careful to call methods like getSherlockActivity() in Fragments instead of getActivity().
I prefer HoloEverywhere library
It allows much more than ActionBarSherlock, but makes your app ~3Mb bigger in size
I am sure you have not seen this
http://developer.android.com/guide/topics/ui/actionbar.html
I am developing a android application.i am using action-bar in my app.but its not working in my Android smartphone(2.2.3) crashing. give me the solution.
Use actionbar sherlock for supporting lower versions too.. follow this
Here is how to use ActionBarSherlock:
Download the ActionBarSherlock here.
Assuming you're using Eclipse IDE, right click your Project, click Properties, then Android. At the bottom, in Layout, Add ActionBarSherlock.
Make sure ActionBarSherlock and your Project are in the same directory.
Extend your classes to Sherlock naming. For example, instead of Activity, change it to Sherlock Activity. The main documentation of ActionBarSherlock is found here.
For easier usage of Sherlock, create util methods in changing the Sherlock names and modifying it.
If you just need to know ocally the android version and act according to it :
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
// do something
}
else {
// do something else
}
Yet another compatibility question.
THE PROBLEM
I need to use a tabbed action bar in api level 3.0 and greater to switch between fragments. However, I also need to be able to switch between these fragments somehow in api level < 3.0.
The spanner in the works is the fact that I have already downloaded a custom compatibility library that allows me to use google maps with fragments and therefore I can't use a library.
THE QUESTION
How can I implement a tabbed ActionBar solution in 3.0 and greater and also cater for the bigger market that is 3.0 and less?
Any help would be grand.
What you want is ActionBarSherlock. It uses the native action bar for API >= 3 and provides backwards compatibility for API levels 2.x. There's also the Action Bar Compatibility sample project (listed as SupportAppNavigation, I believe). I think this is essentially the same thing.
So I managed to figure a solution a while ago, it's just taken me a while to post it here.
This is the solution that works for me. I needed to use an ActionBar but I also needed to use the MapActivity as well as the FragmentActivity hence not being able to use ActionBarSherlock.
What I did was the following:
Created a fragment called CCActionBar which handles the touching of the CCTab's by adding itself as a listener(explained below). It also inflates a layout called action barlayout which has the tabs and images arranged, just reference the tabs at run time.
Created a custom view called CCTab which represent the tabs of the action bar. When its touched it tells its listener (CCActionBar) its been touched.
In my main layout xml file have an action bar container which I show or hide at runtime depending on the API level.
Now in my main activity in my OnCreate method I check whether my API level is greater than 3.0 or not. If it is I just implement the standard ActionBar making sure my custom action bar container is invisible. If it isn't I set up my custom action bar and make sure my action bar container in my xml layout is visible.
Then I make sure that when a tab is pressed whilst using either method it is handled in the same way so once its setup you don't have to handle it any differently.
I hope this helps someone somewhere or at least give you an idea of how to proceed.
What I would recommend is to use ActionBarSherlock to get the tabbed action bar functionality.
I assume that you also need a MapView support in Fragment. For this I would recommend solution from MapView in a Fragment (Honeycomb)
(look at user1414726 answer with sample code).
I think it is a better solution than using library though it is using deprecated LocalActivityManger. But in my opinion it is a better idea than using library where every Activity is a subclass of MapViewActivity which I assume you are using.
I'm using ActionBarCompat in my project.
The problem I have now is that I need a spinner to show in the actionbar. A standard ActionBar can use .setNavigationMode(ActionBar.NAVIGATION_MODE_LIST) but this is unavailable in the action bar compat code.
Is there a way around this? What are other options (besides a layout redesign.)
There is no way to do this in the code provided by ActionBarCompat.
It provides an ActionBar in it's most basic form for use by all platforms.
A better alternative is useing ActionBarSherlock. The setup very similar and more functionality is available out of the box.
http://actionbarsherlock.com/
Is there any way to change the content of the title bar when it's in Tab(If it wasn't in tab I would have done it but tried couldn't find any solution). E.g. Suppose I have created a custom title bar with few buttons on it, and now I want to change the content of the title bar(Drawables, Title and the functionality).
It would be great if someone could tell me if i can implement Action bar in versions below 3.0 ? I am creating this project in 2.1 (I'd like to create action bar from scratch).
or if there's any way beside inserting an image and placing buttons on it(This methodology would be good enough)?
If you're just looking to implement the ActionBar paradigm in pre-Honeycomb versions of Android, I suggest you look into using the ActionBarSherlock library.
The library will automatically use the native action bar when
available 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 back through 1.6.
twaddington and pjco's answers are correct, you need to use ActionBarSherlock if you want to be compatible with every SDK levels.
I want to add you can have a custom actionbar or a custom view for your actionbar tabs using the method actionbar.setCustomView(view) or tab.setCustomView(view)
Anyway, play with ActionBarSherlock demos, there are a few cool use cases.
The other option worth looking at is ActionBarCompat, which I think comes with the SDK 14 api demos. However, ActionBarSherlock seems to support many more features so that may be the better solution.