My Android TabLayout does not occupy full screenwidth when Tabmode is set as scrollable I tried to set mode as fixed and gravity as fill , in that case the font size of text is coming as very small. Please help me regarding this :
Please find my below layout:
TabLayout:
<com.google.android.material.tabs.TabLayout
android:id="@+id/sliding_tabs"
style="@style/tab_style"
android:layout_width="match_parent"
app:tabMaxWidth="0dp"
/>
Styles:
<style name = "tab_style" parent="Widget.MaterialComponents.TabLayout">
<item name="tabGravity">fill</item>
<item name="tabMode">scrollable</item>
<item name="textAllCaps">false</item>
<item name="tabBackground">@color/cg_interactive_elements</item>
<item name="tabTextColor">@color/cg_tab_text_color</item>
<item name="tabIndicatorColor">@color/cg_text_light</item>
<item name="tabTextAppearance">@style/TabText_style</item>
<item name ="tabSelectedTextColor">@color/cg_text_light</item>
<item name ="tabIndicatorHeight">5dp</item>
<item name = "android:layout_height">50dp</item>
<item name = "tabMaxWidth">0dp</item>
</style>
<style name="TabText_style" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
<item name ="android:textSize">16sp</item>
<item name="android:fontFamily">sans-serif</item>
<item name = "fontWeight">200</item>
<item name = "android:fillColor">@color/cg_fill_color</item>
<item name = "borderWidth">4dp</item>
<item name = "android:gravity">center</item>
<item name = "android:textAppearance">@style/TextAppearance.AppCompat.Medium</item>
</style>
Total Layout:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/tablayout_container">
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="106dp"
android:background="@color/cg_header_navigation"
android:id="@+id/app_bar_container">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleMarginTop="13dp"
android:minHeight="?attr/actionBarSize"
app:menu="@menu/top_app_bar"
app:layout_scrollFlags="scroll|enterAlways"
app:titleTextColor="@color/cg_text_light" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/sliding_tabs"
style="@style/tab_style"
android:layout_width="match_parent"
app:tabMaxWidth="0dp"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cg_background"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
/>