One of the key design recommendations in Android 4.0 for tabs is to allow swiping between them where appropriate. This behavior enables users to swipe horizontally across the selected tab’s contents to navigate to adjacent tabs, without needed to directly interact with the tabs themselves.
How can this be implemented?
NOTE: This is an excerpt from the Android Training class Implementing Effective Navigation.
To implement this (in Android 3.0 or above), you can use a ViewPager in conjunction with the ActionBar tabs API.
Upon observing the current page changing, select the corresponding tab. You can set up this behavior using an ViewPager.OnPageChangeListener in your activity’s
onCreate()method:And upon selecting a tab, switch to the corresponding page in the ViewPager. To do this, add an ActionBar.TabListener to your tab when creating it using the
newTab()method: