Android – Build tab layout with FragmentPagerAdapter, ViewPager and ActionBar

Tab control is a popular component in desktop application. I think, most of desktop application contains at least a tab control in one way or another. In Android environment, we also have a tab control named “TabHost”, but since Android 3.0, it was replaced by ActionBar. In this post I would like to show how we can make a “fake” tab layout with ActionBar so that we can give user the same experience like TabHost. This control is built up by a combination of ActionBar and FragmentPagerAdapter. The labels will be located at the top, switching between tabs will load the content of the tabs. Moreover thanks to touch screen of smartphone, user can also swipe to navigate between tabs. The final result of our “fake” tab layout looks like following image (Please note that we aren’t going to make a “tab control” but a “tab layout”, they are different concepts)

Continue reading Android – Build tab layout with FragmentPagerAdapter, ViewPager and ActionBar