I am trying to implement the tablayout as the following design-

I could design as this-
Could anyone please help me to achieve the following points?
- When a tab is selected, the background should fill the 1st half or the 2nd half of the tab.
- For a selected tab item, there is a small margin for the background. It should not completely fill the tab.
Code: MainActvity.xml
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab"
android:layout_width="440sp"
android:layout_height="64sp"
android:layout_marginTop="100dp"
android:layout_marginBottom="101dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="@drawable/backGroundWithWhiteBorder"
style="@style/customTabLayout"
app:tabBackground="@drawable/tab_color_selector" />
tab_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@color/tiffany_blue" />
<item android:drawable="@color/transparent" />
</selector>
backGroundWithWhiteBorder.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="376dp"
android:height="64dp"
android:viewportWidth="376"
android:viewportHeight="64">
<path
android:strokeWidth="1"
android:fillColor="#00000000"
android:strokeColor="#fff"/>
</vector>
Style.xml
<style name="customTabLayout" parent="Widget.Design.TabLayout">
<item name="tabTextAppearance">@style/TabText</item>
</style>
<style name="TabText" parent="@android:style/TextAppearance.Widget.TabWidget">
<item name="android:textAllCaps">false</item>
<item name="android:textSize">30sp</item>
<item name="android:textAlignment">center</item>
</style>

You can achieve this kind of
TabLayoutwith aMaterialCardViewas the parent and theTabLayoutas the child of it. To draw the outer rectangle section you can simply use the propertiesapp:strokeWidthandapp:strokeColorto draw the border and you can move theTabLayoutinside theMaterialCardViewusing theandroid:layout_marginproperty.Example:
where
@drawable/tabs_selectoris the drawable tabBackground selector:and
@style/CustomTabTextAppearanceis used to set a custom Tab Text Appearance:Result: