This project explore the use of SlidingTabLayout to create Material Design Tabs.
In order to use the SlidingTabLayout, we first have to get SildingTabLayout.java and SlidingTabStrip.java from Google's open source I/O app and add it to the project.
In this project, we will using Toolbar, and ViewPager so we need to add the following file into build.gradle:
- compile 'com.android.support:appcompat-v7:23.0.1'
- compile 'com.android.support:support-v4:23.0.1'
We will have a lot of layout files:
- The layout of the main acitivty
- each individual fragmentand
- color attribute for toolbar
- style for toolbar
The most important one is the main activity, which is consist of toolbar(at the top), then SlidingTabLayout, then ViewPager(where we swip our fragment)
we will create each individual fragment for different tabs and ViewPager will manage the fragment based on user's action.
we will create a custom ViewPagerAdapter for ViewPager so it can manage the fragment for each tab.
Inside the main activity, we will combine our toolbar, slideTabLayout, and ViewPager together.
- find the toolbar and set it as the actionbar for the activity.
- create the ViewPagerAdapter and set it to our ViewPager.
- find the SlidingTabLayout and set the color for tabScroller.
- set the ViewPager for SlidingTabLayout.