TabLayout using ViewPager

Example:

                                    
                                        <!-- activity_main.xml -->

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<!-- TabLayout to display tabs -->
<com.google.android.material.tabs.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabTextColor="#FFFFFF"
    android:background="#5D0000"
    app:tabIndicatorHeight="5dp"
    app:tabSelectedTextColor="#000000"/>

<!-- View pager to swipe views -->
<androidx.viewpager.widget.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>


<!-- fragment_my.xml -->

<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"
    android:gravity="center"
    android:background="#555100"
    tools:context=".MyFragment">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Tab"
        android:textSize="28sp"
        android:textStyle="bold"
        android:textColor="#FFFFFF"/>

</RelativeLayout>