Disable TabLayout

前端 未结 11 1848
时光说笑
时光说笑 2020-11-29 02:49

I\'m using the new class provided by the design library : TabLayout. And I want in specific cases that the one I\'m using can\'t change tab anymore.

I manage to disa

11条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 03:22

    Based on Michele's Accepted Answer, to disable click for a single tab in Kotlin:

    Inside the tabs-containing activity:

    val tabs: TabLayout = findViewById(R.id.tabs)
    ...
    
    (tabs.getChildAt(0) as LinearLayout).getChildAt(desiredTabPositionHere).isClickable = false
    

    Inside the fragments (tabs):

    (requireActivity().tabs.getChildAt(0) as LinearLayout).getChildAt(desiredTabPositionHere).isClickable = false
    

    You can turn the click function on and off (by setting true or false). With the same method, it is also possible to modify visibility, alpha, backgroundColor etc.

提交回复
热议问题