0

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"/>
4
  • cover your TabLayout with horizontalscrollview. And set styles
    – S T
    Commented Jun 10, 2020 at 2:09
  • you mean, place tablayout inside a horizontalscrollview parent? Commented Jun 10, 2020 at 4:59
  • yes that is what i mean
    – S T
    Commented Jun 10, 2020 at 5:01
  • I can get the horizontal scrollbar to show if I add a horizontal scollview parent, but the problem is that the tablayout method: setScrollPosition() does not make the tablayout visibly scroll to the correct position (although the selected tab does update). Commented Jun 23, 2020 at 23:35

3 Answers 3

2

just this code : app:tabMode="scrollable"

1

Try to set indicator height.

app:tabIndicatorHeight="5dp" 
1
  • no, that sets the active tab indicator height. I mean the scroll position % indicator. Commented Jun 10, 2020 at 4:17
0

Use this code:

tabLayout.setHorizontalScrollBarEnabled(true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.