How to make tab title alignment to left in TabLayout in Android

Naman picture Naman · Aug 25, 2016 · Viewed 8.5k times · Source

I can't seem to align my tab titles to the left, inside my TabLayout. At the moment, the titles are centered. Here is what I want to achieve.

And this is what I have at the moment. The code I'm using is as follows:

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    app:tabGravity="fill"
    app:tabMode="fixed"
    app:tabTextColor="@color/white"
    app:tabSelectedTextColor="@color/white"
    app:tabIndicatorColor="@color/white"
    android:background="@color/slate_grey"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>

Answer

Elvis Chweya picture Elvis Chweya · Aug 25, 2016

add app:tabMode="scrollable" to your <TabLayout.../> and don't forget to add xmlns:app="http://schemas.android.com/apk/res-auto" too.

For more info check out https://developer.android.com/reference/android/support/design/widget/TabLayout.html