1

I have tabs inside TabLayout and sometimes I need disable some tab, for example tab1 (I don´t need disable all of them, only some of them). Disable means it is not possible tap on it. How can I do that?

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/switchLayout"
        android:layout_width="match_parent">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout="@layout/custom" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout="@layout/custom" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tab3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout="@layout/custom" />

    </com.google.android.material.tabs.TabLayout>
Michalsx
  • 3,446
  • 5
  • 33
  • 46

1 Answers1

0

Try this if it works:

touchableList = tabLayout?.touchables
touchableList?.forEach { it.isEnabled = false }

Or you could refer to this:

How can I disable click on TabLayout in Android

Miriana Itani
  • 865
  • 9
  • 25
  • Thank you for showing me direction. Using touchables doesn´t seem to be good idea, because I must say on which position I want to disable it and disabling with touchables messing with position. Therefore I tried to use setOnTouchListener and it works, thank you. – Michalsx Jul 15 '20 at 18:48
  • glad to know it help – Miriana Itani Jul 16 '20 at 05:45