Rowan Gontier
Rowan Gontier

Reputation: 885

How to show scrollbar for tablayout?

I need to show a scrollbar on a horizontally scrolling tab layout.

I have tried the following without success:

        <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tabLayout"

                    app:tabMode="scrollable"
                    android:scrollIndicators="bottom"
                    android:scrollbarTrackHorizontal="@color/black"
                    android:scrollbars="horizontal"
                    android:scrollbarSize="2dp"
                    android:isScrollContainer="true"
                    android:scrollbarFadeDuration="0"
                    android:scrollbarAlwaysDrawHorizontalTrack="true"
                    android:scrollbarStyle="insideOverlay"
                    android:scrollbarThumbHorizontal="@android:color/darker_gray"

    //Not relevant parts below
   app:tabSelectedTextColor="@color/blue"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintLeft_toLeftOf="parent"
                    app:layout_constraintRight_toRightOf="parent"
                    app:tabTextAppearance="@style/TabTextAppearance"
                    android:background="@color/white"
                    android:visibility="visible"
                    android:backgroundTint="@color/very_light_gray"
                    app:tabIndicatorColor="@color/blue"/>

Upvotes: 0

Views: 1332

Answers (3)

Usama Zahid
Usama Zahid

Reputation: 3

Use this code:

tabLayout.setHorizontalScrollBarEnabled(true);

Upvotes: 0

Genius8020
Genius8020

Reputation: 145

just this code : app:tabMode="scrollable"

Upvotes: 2

igarasi
igarasi

Reputation: 137

Try to set indicator height.

app:tabIndicatorHeight="5dp" 

Upvotes: 1

Related Questions