Here are the steps to set the Tab background color:
first the code and then some brief explanation:
The code:
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:tabBackground="@drawable/tab_background_color_selector"
app:tabIconTint="@color/tab_content_color_selector"
app:tabIndicator="@null"
app:tabSelectedTextColor="@color/md_white_1000"
app:tabTextColor="@color/secondaryColor">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_list"
android:text="list" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/ic_calender"
android:text="calender" />
</com.google.android.material.tabs.TabLayout>
drawable/tab_background_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/secondaryColor" android:state_selected="true" />
<item android:drawable="@color/md_white_1000" />
</selector>
color/tab_content_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/md_white_1000" android:state_selected="true" />
<item android:color="@color/secondaryColor" />
</selector>
The Explanation
tabBackground: is the tab background and should be a drawable selector.
tabIconTint: is for icon color and it must me color selector.
tabIndicator="@null" : as it is useless in this case.
tabSelectedTextColor, tabTextColor are self explanatory.