Reputation: 183
I tried several solutions but nothing worked. The tab bar doesn't fill the width of the parent on some devices. It works fine on devices like Samsung Tab 2 and doesn't work on devices like pixel 2(Like the image attached).
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextAppearance="@style/MyTabLayoutTextAppearance"
app:layout_constraintBottom_toBottomOf="parent"
app:tabIndicatorColor="@color/colorBackground"
app:tabMode="scrollable"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabSelectedTextColor="@color/colorPrimary"
/>
`
Upvotes: 1
Views: 217
Reputation: 363895
You have to use also the app:tabMode="fixed"
attribute.
Something like:
<com.google.android.material.tabs.TabLayout
app:tabGravity="fill"
app:tabMode="fixed"
..>
Check also the doc: In the support design library:
Gravity used to fill the
TabLayout
as much as possible. This option only takes effect when used withMODE_FIXED
.
With the Material Components Library:
Gravity used to fill the
TabLayout
as much as possible. This option only takes effect when used withMODE_FIXED
on non-landscape screens less than600dp
wide.
Upvotes: 2