Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding of TabLayout tabs to an activity which already has a ViewPager (swipe views). TabLayout is the new standard way to add tabs to an activity. TabLayout is added like any other UI element in the activity's layout, and can then be very easily integrated with the activity's ViewPager. The TabLayout class is in the Design Support Library, which must be added to the project dependencies in the module's build.gradle file: dependencies { compile 'com.android.support:design:24.2.1' } To implement TabLayout tabs, the following steps are necessary: - Make sure the project includes the Design Support Library - Add a <TabLayout> element between the <Toolbar> and the <ViewPager> elements of the activity's layout - In the activity's onCreate method, call setupWithViewPager(viewPager) on the TabLayout reference - Make sure the PagerAdapter overrides the getPageTitle method (this is needed for setupWithViewPager to work) That's it. The tabs in the TabLayout are automatically populated and linked with the ViewPager by setupWithViewPager, and everything works. References: https://developer.android.com/reference/android/support/design/widget/TabLayout.html
- Loading branch information