I want to setup a 'tabbed' application. Looking through all the tutorials including the google docs here:
http://developer.android.com/training/implementing-navigation/lateral.html
However as I start to go through the docs I get all kinds of deprecated warnings:
actionBar.setSelectedNavigationItem(position);
I would really like to start off right and use any new non deprecated methods. Most examples of tab applications are years old. What am I missing? Am I searching for the wrong thing? Can someone point me in the right direction for developing a tabbed application.
What am I missing?
Action bar tabs were deprecated in Android 5.0, last fall.
Can someone point me in the right direction for developing a tabbed application.
Use TabLayout, though this is a very new addition to the Android Support libraries.
Or, use ViewPager with your favorite tabbed indicator, of which there are many.
Or, use FragmentTabHost.
Related
I'm a long-time Windows developer who is now doing Android development.
I would like to use the exact functionality contained in the following officially documented example on tabs and swipe:
http://developer.android.com/training/implementing-navigation/lateral.html
Deprecated Functionality
However, the downloadable example contains methods & functionality which is deprecated.
I'm confused about why the Android official example which shows how to handle tabs and swiping ends up including code which is deprecated.
Is it not the most recent version?
What Functionality Am I Looking For?
I'll show you two screen shots which display tabs and allow the user to select the tabs to navigate among them or swipe left or right to move through them.
Looks like the following:
I want the user to be able to easily switch between the two tabs and I have a plan to indicate to the user that information on the other tab has been updated by displaying an icon on the current tab.
My Main Question
Is there a similar example which does not include these deprecated
methods?
Related Questions
If I choose to implement the code in my application -- because the solution is quite beautiful and looks easy to implement -- what will the consequences be?
Does it mean that some time in the future the application wouldn't even work properly?
Does it mean that it may not work on some devices (API versions)?
Here's some of the code which is deprecated:
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
actionBar.setSelectedNavigationItem(position);
actionBar.addTab();
actionBar.newTab();
It seems that the deprecated functionality is actually related to the ActionBar.
After quite a bit of searching, I found a better example of what I wanted -- sans ActionBar and sans deprecated functionality :
http://developer.android.com/samples/SlidingTabsBasic/index.html
When you get to that page, you will see that there is no documentation for the subject. It's odd. Look very closely in the upper right corner and you'll see a download link which will allow you to download a sample. It looks like:
The sliding tab solution is even more elegant and does not include any deprecated functionality.
Here's what it looks like:
The example is fantastic, because you can traverse through the tabs by swiping the bottom panel. Or you can click any of the tabs to move to the associated tab.
Also, the example gives you some more fucntionality above the tabs with the Show Log menu item which switches out the top portion.
Definitely worth a look and this answers my question.
Hope this helps someone else who is looking.
I'm confused about why the Android official example which shows how to handle tabs and swiping ends up including code which is deprecated.
Not all documentation gets updated. There has been stuff that has been out of date for years on the site, and despite filing issues, it does not get fixed. This is not unique to Android; it is reasonably commonplace in software development.
Is it not the most recent version?
It is the most recent version.
Is there a similar example which does not include these deprecated methods?
I do not know what qualifies as an "example". There are many, many implementations of tabs for ViewPager, both from Google (TabLayout) and from third parties (about half of the entries in the "View Pagers" category in the Android Arsenal). Some of those third-party libraries have sample projects as part of their repositories.
Does it mean that some time in the future the application wouldn't even work properly?
Quite possibly, particularly depending upon your definition of "work properly". We have no means of knowing exactly what will happen in the future (as we used up our last flux capacitor a week ago). Deprecated stuff usually keeps working, but it is at somewhat greater risk of bugs simply due to no longer being aggressively maintained. In the case of action bar tabs, the appcompat-v7 action bar backport does not support them at all.
As far as I know, there are components ViewPager and ActionBar can support "tab navigation" mode but they don't have intermediate tab indicator between the tabs, just only positioning below a tab TextView.
How the Google Play app implemented this feature: POSITIONING linked with transition ?
You can achieve this by implementing android:actionBarTabStyle using ActionBarSherlock library.
Update:
I don't have idea exactly about this, but hope you know Android team has integrated the same pattern in I/O 2013 Android app and it will open sourced soon.
Update 2:
I just came across one library which can fulfill your requirement, check this: https://github.com/astuetz/PagerSlidingTabStrip
I am trying to implement an ActionBar into my existing project but don't know where to start. I immediately started building a classic menu button menu, before I realized that it is deprecated and some devices (nexus 7) can't access such menus.
What is a good way of implementing an ActionBar over a map? I am already deep into this project and it is due in a couple of days so rewriting the program is not really an option.
What I am really looking for is two or three simple options always available at the top or bottom of the map which extend to a list if clicked. Thanks !
For implementing ActionBar in a back-compatible way you would probably want to use ActionBarSherlock and its Maps plugin.
Take a look at its samples, it's pretty simple to use.
I've been slowly porting my iOS App to Android so I can take my time and make sure that it functions correctly and I'm now at the part where I need to create a TabBarController like environment. I've been searching for days and have come across numerous examples but with each example there's a problem.
First, most examples refer to using a TabActivity, which when I just checked is deprecated and can't be used. The one's that don't use TabActivity either use Fragments (sometimes with an Action Bar) or a Tab Host. It looks like Fragments is the way to go, but then how to you support older devices (from the Android website over 50% of there users are still on API 10).
Basically what I need to set up is a Tabbed environment that will let each tab load a new Activity, and then each of those Activities will have their own navigation based hierarchy as well so I'm trying to see what is the best option to pursue and if anyone has seen some examples that can help.
I've found 4 tutorials so far that have fragments and different activities for each Tab, so I'm going to look into those now but just wanted to see if any other developers that have already come across and issue like this did to work with the compatibility issues with older devices.
You can use Fragments all the way down to API 4 using the Support Library. I'd use a single Activity with multiple Fragments in ActionBar tabs, though you might need to do it with TabHost to support lower APIs.
I got stuck with Jake Wharton ViewPagerIndicator.
The problem is that when I try to make a Tab indicator - the result I'm getting is extremely different from what I need and I can't get to style it or make it behave as it should.
So, what I ask for is two things:
1) Am I right when I say that TabIndicator is Foursquare-like ViewPagerIndicator? (when all tabs are shown on screen)
2) Can anyone provide me links to some tutorials or samples of using this type of ViewPagerIndicator, cause samples from JWs' site don't want to get working.
Thanks a lot for your attention!
Jake Wharton provides a lot of examples. Have you checked it?
https://github.com/JakeWharton/Android-ViewPagerIndicator
And you can take a preview installing this apk:
https://play.google.com/store/apps/details?id=com.viewpagerindicator.sample&hl=es
moskis is right on about ViewPagerIndicator. Installing that APK helped me a lot when I first started working with it and it is a great library.
However, to answer the first part of your question and what I think you are asking in general, I think ViewPagerIndicator isn't what you need to solve this specific problem. Foursquare's tabs at the top are the standard Android tabs as shown in http://developer.android.com/design/building-blocks/tabs.html.
Standard Android tabs are implemented using a TabHost and TabWidget. There is an official tutorial about creating a tabbed interface at http://developer.android.com/guide/topics/ui/layout/tabs.html
Foursquare achieves a custom look by providing state-list drawables for the tabs and you will probably want to provide your own to get the style that you want for your app.
Note that I don't have access to the Foursquare implementation, but am going off of what I observe whiel using the app. However, I have implemented a tabbed interface for Android in past projects.