Roman
Roman

Reputation: 2733

How to left align the tab text of TabLayout in Android

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

Upvotes: 1

Views: 1189

Answers (2)

Vijay S
Vijay S

Reputation: 418

Check this

app:tabGravity="start"

Upvotes: 1

Taranmeet Singh
Taranmeet Singh

Reputation: 1239

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);
    }

Upvotes: 2

Related Questions