一、实现思路
1、在build.gradle中添加依赖,例如:
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
也可以将support-v4替换为appcompat-v7,例如:
compile 'com.android.support:appcompat-v7:23.4.0'
因为appcompat-v7是依赖于support-v4的。
更多说明可参考官方文档support library部分。
2、在xml中添加TabLayout和ViewPager,例如:
xmlns:tool="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tool:context=".TabViewActivity"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tabLayoutBackground"
app:tabMode="scrollable"
app:tabTextColor="@color/color_white"
app:tabSelectedTextColor="@color/tabSelectedText"
app:tabIndicatorHeight="3dp"
app:tabIndicatorColor="@color/color_white"/>
android:id="@+id/view_pager"
android:layout_width=