Rupesh
Rupesh

Reputation: 183

tab icons not filling full width

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).

strong text

<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

Answers (2)

Jakir Hossain
Jakir Hossain

Reputation: 3930

Usefixed tabMode instead of scrollable

app:tabMode="fixed"

Upvotes: 1

Gabriele Mariotti
Gabriele Mariotti

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"
      ..>

enter image description here

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 with MODE_FIXED.

With the Material Components Library:

Gravity used to fill the TabLayout as much as possible. This option only takes effect when used with MODE_FIXED on non-landscape screens less than 600dp wide.

Upvotes: 2

Related Questions