Swipe between native ActionBar tabs containing fragments in ICS - android

Is there a native way to swipe/fling between different ActionBar tabs (the Honeycomb/ICS native one) containing fragments (one per tab)?
I know of the Android Compatibility package, which is used by this solution provided by Google itself. But I don't want to add the whole library just to use one simple and very common usability pattern.
Even the brand new Android Design Guide advocated swiping between ActionBar tabs, but without mentioning a way to do it natively in Honeycomb or Ice Cream Sandwich.

Is there a native way to swipe/fling between different ActionBar tabs (the Honeycomb/ICS native one) containing fragments (one per tab)?
If by "tab" you mean "tab" (i.e., the thing the user taps on), then tabs will be swipe-able automatically by the OS when it lets you. If you have more tabs than there is room for in the action bar, either the user can swipe back and forth (normal-size screen in portrait), or the tabs will be converted into a Spinner-style drop-down list (normal-size screen in landscape, or both orientations on large/xlarge-size screens).
If by "tab" you mean "tab content" (i.e., the thing that takes up the bulk of the screen), then tabs are not swipeable unless you handle that yourself (e.g., ViewPager).

Related

Non-sliding TabLayout

I am currently rewriting one of my iOS apps for Android, and I am working on adding tabbed navigation. The problem is, I haven't found a way to integrate tabs into an Android app without them being sliding (swipe left and right to switch tabs).
In the iOS version of my app, the middle of the three tabs contains a full-screen map view, so obviously in Android with the sliding tabs, the middle tab would not be slidable. I don't want this, as I would like to maintain consistency between the tabs.
Is there a way to deactivate the sliding on tabs? Or is there a way I could intercept the gesture in a similar way to the way a map would absorb it?
so obviously in Android with the sliding tabs, the middle tab would not be slidable
Actually, by default, it would be swipeable, though this would mean that the user cannot pan around the map. You have to take special steps to make a MapView get the touch events instead of the ViewPager, for reasons I have never fully understood.
I haven't found a way to integrate tabs into an Android app without them being sliding (swipe left and right to switch tabs)
Use FragmentTabHost. Or, use TabHost. Or, write your own tab implementation that toggles the visible view or fragment.
Note, though, that your users may expect to be able to swipe between tabs, if the tab content itself is not something that obviously would take precedence (e.g., the map). Users may prefer that your app be consistent with other Android apps, rather than be consistent with an app (your iOS app) that none of them use.

Slidable tab navigation depending on the screen size

I am looking for a Tab navigation UI component that would work similarly to the SlidingPaneLayout, i.e. would show as many tabs as possible and make the tabs slidable left/right when the tabs wouldn't fit on the screen (in my case its tablets vs smartphones case). An example of it would be Slideable top navigation UI pattern.
Is there any library I could use to implement such component in my app?
Action bar tabs and ViewPager are the one's you are looking for. These are in built feature of Android, Easy to access and backward compatible to earlier versions as well.
ActionBar tabs is the one that will give you the tab like feature.
ViewPager on the other hand will provide the functionality of swipe.
Here is a step by step example on both.

How to structure code for Activitys in a tabhost and actionbars

I want to have a few pages under a tabhost. The pages with the tabs, are accessed on about page 2/3 after application start. I am confused in how to link to the first page of the tabhost (from a page without a tabhost)
Each tab in the tabhost is a separate activity.
So when it's time to send user to a page in the tabhost, do I start the Tabhost activity (from extends TabActivity), create the tabhost, then... somehow choose which page in the tab to load? like tabhost.myTab.trigger.start(); INSTEAD of just loading one of the tabs activities directly..
So therefore anytime you leave the tabhost, and come back to it , you are recreating it, is this the correct way to structure things?
Thanks!
The TabHost method is considered a pretty old way of creating tabs within your Android application. This is especially so if you're placing Activities within those tabs.
A modern Android application uses Fragments, and uses the Action Bar framework to place those Fragments within tabs.
This can be done easily from your main Activity by using
getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
This has several advantages. It means your Fragments can be placed inside of a ViewPager (so the user can swipe between them). It also means that your tabs will adapt to the device they're running on. (On a phone they may appear below the Action Bar, but on a tablet they actually become part of the Action Bar).
Depending on your implementation, this can be done is such a way that navigating between tabs does not cause the Fragments to be recreated (if that's what you're after).
A detailed guide on how to implement Action Bar Tabs can be found here
If backwards compatibility is a concern, then check out the amazing Action Bar Sherlock library.
I don't fully understand the behavior you are trying to accomplish.
Though, if you don't want to reinvent the wheel, i would recommend you to install the ActionBarSherlock demo apps1 to check if the desired behavior is already implemented as one of the library examples. If it's already done, then you can go to the github project to take a look at the source code, learn how it's done, and contribute with it.
Action Bar Sherlock demos
https://play.google.com/store/apps/details?id=com.actionbarsherlock.sample.demos&hl=en
Action Bar Sherlock Fragment demos
https://play.google.com/store/apps/details?id=com.actionbarsherlock.sample.fragments&hl=en

Using both list navigation and tabs with ActionBarSherlock?

I'm looking through the ActionBarSherlock samples demo, and I see that the List Navigation and the Tab Navigation both make use of the ActionBar's setNavigationMode method. This tells me that you can only have one or the other. If I want the user to have list navigation to move around between activities but I want some activities to have tabs, is there a different way to add tabs than via navigation mode? Is it against ActionBar design guidelines to use both? I don't look at tabs and consider this to be a navigation feature, so I find it odd that you get one or the other.
This tells me that you can only have one or the other
Correct. Bear in mind that with action bar tabs, Android will convert you to list navigation, on its own, in certain configurations, whether you like it or not.
If I want the user to have list navigation to move around between activities but I want some activities to have tabs, is there a different way to add tabs than via navigation mode?
You can use a ViewPager with PagerTabStrip or the tab flavor of ViewPagerIndicator.
Or, you can go retro and use TabHost and TabWidget.
Is it against ActionBar design guidelines to use both?
The design guidelines refer to them as separate options for "View Controls". More importantly, given the automatic conversion of tab navigation to list navigation, it would be seriously confusing for the action bar to have two Spinners' worth of navigation choices.

What is the recommended navigation approach in Android for navigating between disparate activities/fragments

I am switching my Android app over to a more "proper" UX with the ActionBar etc. I have been trying to determine what the best/recommended navigation style would be.
My app has 5 activities that I currently switch between by using the menu/overflow menu.
My app has 1 main home screen that the user will spend most of their time on. The user needs a way to navigate to the other activities but none of them are really related to eachother. They are more like utility screens that a user will go to when they need to do some maintenance.
I am reading this link: http://developer.android.com/design/patterns/actionbar.html
I was first thinking to use an action bar dropdown navigation but that seems like it's not designed for navigation and more so for switching between views of the same data:
Use a spinner in the main action bar if:
You don't want to give up the vertical screen real estate for a dedicated tab bar.
The user is switching between views of the same data set (for example: calendar events viewed by day, week, or month) or data sets of the same type (such as content for two different accounts).
Then I was going to use ActionBar tabs but it says that is more for swiping between items that are used often:
Use tabs if:
You expect your app's users to switch views frequently.
You want the user to be highly aware of the alternate views.
I guess the last option is to put the actions into the overflow menu but this seems like i'm going backwards.
Can anyone offer some insight?
Thanks
I have decided to go with a side drawer as per here:
http://developer.android.com/design/patterns/actionbar.html
Open a drawer from the main action bar if:
You want to provide direct navigation to a number of views within your app which don't have direct relationships between each other.

Categories

Resources