提问者:小点点

如何禁用单击TabLayout内的TabItem? [副本]


我在TabLayout中有一些选项卡,有时我需要禁用一些选项卡,例如tab1(我不需要禁用所有选项卡,只需要禁用其中一些选项卡)。 Disable表示不可能点击它。 我怎么能那么做?

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

共1个答案

匿名用户

如果有用,请试试:

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

或者你可以参考这个:

如何在Android中禁用单击TabLayout