I'm working on an android sample project, which makes use of TabActivity. But as this is deprecated now, I replaced it with the 'Fragment' activity. Now I don't know what to use, to replace,
TabHost tabHost = getTabHost()
which I had used while using TabActivity.
Also, setContentView(R.layout.main)
and setClass() in intent = new Intent().setClass() is giving an error.
You could use Action Bar Sherlock. This open source library gives you an action bar for every Android Version down to 1.6
This enables you to create tabs in the Honeycomb style with the Honeycomb APIs, therefore you do not need to use the deprecated tab APIs.
Related
I have a problem with ActionBar.
I set minsdk in AndroidManifest to 14. Next I create Activity (BlankActivity), thats create MyACtivity class which extend ActionBarActivity and import android.support.v7.app.ActionBarActivity. I think that this library need only if you use sdk level 7 or lower.
This import correctly? Or i need use another extend class?
And I try change extend class to Activity, but its does not create ActionBar on Activity.
How add ActionBar on this Activity?
P.S. I was misled, because on my sdk function getActionBar must work, its NullPointer, because my app use this strange import. A can use getSupportActionBar, but its strange use support library for sdk 7 to create Application for sdk 14 or higher.
P.S.S. Thanks!!
If anybody have same problen, there is some links about toolbar:
http://www.101apps.co.za/index.php/articles/using-toolbars-in-your-apps.html
Why was ActionBarActivity deprecated
I have a problem with ActionBar.
Who doesn't ;)
I think that this library need only if you use sdk level 7 or lower.
The appcompat-v7 library used to backport API 14 Action Bar to platforms below that. APIs 7 through 13 used this reimplementation, APIs from 14 used native Action Bar.
Since Lollipop the appcompat-v7 always uses it's own implementation of Action Bar and backports Material theme from Lollipop.
This import correctly? Or i need use another extend class?
To have the Action Bar with appcompat-v7 your activity class must extend AppCompatActivity (previously ActionBarActivity) and it's theme must descend from Theme.AppCompat.* family.
And I try change extend class to Activity, but its does not create ActionBar on Activity.
Native activities on Lollipop don't have any Action Bar by default. You would supply it by having a Toolbar widget in your layout and calling setActionBar(Toolbar). Similar approach can also be used with appcompat-v7 (if you use a theme without default action bar) by calling setSupportActionBar(Toolbar).
How add ActionBar on this Activity?
[...] but its strange use support library for sdk 7 to create Application for sdk 14 or higher.
It's perfectly OK, the goal is to make the app look the same from API 7 to API 22. Appcompat-v7 now backports not only the Action Bar but Material theme as well.
It's better you start with a working example. Just check in you android sdk installation for the folder \samples\android-21\ui\ActionBarCompat-Basic.
The use of the support library is correct, just follow the ActionBar Developer guide here.
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'm trying to implement an activity which will include TabHost and each tab in it will run\represent a different Activity so if the user press on tab #1 he'll see Activity A and if he'll press on tab #2 he'll see Activity B.
I don't want to use TabActivity as it been deprecated but the new API FragmentTabHost just doesn't seem to be the right answer\implementation (i need to support OS 2.2 and later).
Does anyone have a good idea\example how to do it?
Thx
Don't use TabHost anymore. Use the new ActionBar API with ActionBarSherlock.
To support Fragments down to Android 2.2 you have to use the Android Support Library.
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.
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.