I am looking for best practice of using tab navigation with sherlock actionbar. What is the proper way of changing the fragments, and adding fragments to the backstack and clearing the back stack when another tab is selected.
Are there any good examples or open source projects showing how to do it right?
Use tabs to alternate between views within the same context, not to navigate to different areas. This is the single most important point, because staying in place while alternating views is the reason we have tabs in the first place.
Use the Tab key on your keyboard to navigate the options on a page. Use Shift + Tab to return to a previous option. Learning Environment highlights page elements that you can interact with (such as links, fields and buttons) as you tab through them, to make it easier for you to complete tasks and select options.
In general, use three to five tabs in iOS; use a few more in iPadOS and tvOS if necessary. Keep tabs visible even when their content is unavailable. If tabs are enabled in some cases but not in others, your app's interface might appear unstable and unpredictable.
I wouldn't use ABS directly to do that. You will run into trouble once your tabs require fragment switching etc. I think the right approach to do this is to use ViewPagerIndicator, which is compatible with ABS. As bonus you also get the swipe right-left between tabs. You need the compat package (like for ABS), example usage you can find in the samples folder.
As Edgar mentioned the android navigation guide is a good place to start. But let me add some comments to how tabs is intended to work with android.
The new acitonbar tabs should be implemented in the same way as it works in the google play app. This means as soon as you want some detail of some content within a tab you'll go to a new view/fragment/activity and the tabs will disappear.
So the tabs for android shouldn't be visible all the time but only in the top hierarchy. If you want to ease the navigation for the user, you'll implement the up button so the user quickly can get back to the top hierarchy, where the tabs are visible.
Tutorial and samples
My personal favorite example and tutorial is the tabs tutorial under the actionbar tutorial on googles webpage.
Examples of tab navigation can also be found in the samples project that come with the android-sdk. Go to: android-sdk\extras\android\support\samples\Support4Demos\src\com\example\android\supportv4\app
And look for: FragmentTabs.java
or FragmentTabsPager.java
.
If you want to use ActionBarSherlock you can also download ActionBarSherlock and look at the samples folder in the /samples directory. In there you have tab demoes in TabNavigation.java
and TabNavigationCollapsed.java
. Though I think you should give the actionbar tutorial a shot.
Tabs with back stack
Also lets say you want to have a tab bar that is visible all the time (though it isn't recommended). Then you have to make a custom back stack for each tab, You can look here for an example of how to implement that.
Maps and tabs
Take a look at all Googles apps that use Map. Google use overflow actionbar buttons in order to navigate around with. So should we as developers but with Google mapsv2 for Android tabs with maps has become much easier if anyone should desire to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With