一、效果图
通过TabLayout和ViewPager这两个控件可以实现Tab切换的效果。而且能通过属性设置来设定滑动条的高度和颜色、字体的颜色等。效果如图所示。
二、Android布局文件
Activity的布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/white"
app:tabIndicatorColor="?attr/colorPrimary"
app:tabIndicatorHeight="5dp"
app:tabSelectedTextColor="?attr/colorPrimary"
app:tabTextColor="@android:color/darker_gray"/>
<!--
app:tabIndicatorColor="@color/colorAccent"设置指示器滑动条的颜色
app:tabIndicatorHeight="5dp" 设置滑动条的高度
app:tabSelectedTextColor="#000" 设置当前页卡的标题颜色
app:tabTextColor="#fff"设置页卡标题颜色
-->