Search code examples
androidandroid-viewpagerscrollbarandroid-tablayout

How to remove scrollbar on TabLayout with ViewPager2?


Here is my tab layout with videpager2 -

enter image description here

here is my XML -

<androidx.appcompat.widget.Toolbar
        android:id="@+id/activity_dashboard_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:titleTextColor="@color/transparent">

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:src="@drawable/user_default_image"
            app:civ_border_color="@color/black"
            app:civ_border_width="1dp" />

    </androidx.appcompat.widget.Toolbar>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/activity_dashboard_tablayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        app:layout_constraintTop_toBottomOf="@+id/activity_dashboard_toolbar"
        app:tabGravity="fill"
        app:tabMode="fixed"
        app:tabSelectedTextColor="@color/current_tab_text_color"
        app:tabTextColor="@color/black" />

I want to remove the scrollbar completly. I don't want to see it at all. I tried android:scrollbars="none" and it did not make any differents. How do I accomplish such behavior?


Solution

  • Setting the Tab indicator (the line is not a scrollbar but indicator) drawable to null seems to work

    
    tabLayout = findViewById(R.id.tabLayout);
    tabLayout.setSelectedTabIndicator(null);
    
    

    or in xml both these seem to do the same

    app:tabIndicator="@null"
    
    app:tabIndicatorHeight="0dp"
    

    though setting the height is deprecated according to the docs