Home > other >  How to left align the tab text of TabLayout in Android
How to left align the tab text of TabLayout in Android

Time:10-19

I need to left align of the tab text inside tab layout.

<com.google.android.material.tabs.TabLayout
    android:id="@ id/tabs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_green_dark"
    auto:tabMode="scrollable" />

CodePudding user response:

You can either inflate a custom view in the tab layout as shown here

or you can run a for loop over all tab items and set the gravity of indivisual textview inside the tab layout like this

for (int i = 0; i < tabLayout.getTabCount(); i  ) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        tab.view.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    }

CodePudding user response:

Check this

app:tabGravity="start"
  • Related