1. 效果预览
2. 在布局文件中放置 TabLayout 和 ViewPager
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<!--
app:tabSelectedTextColor - 设置文字被选中后的颜色
app:tabIndicatorColor - 设置指示器颜色
app:tabIndicatorHeight - 设置指示器高度
-->
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_message"
app:tabSelectedTextColor="