Disable TabLayout

前端 未结 11 1858
时光说笑
时光说笑 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:33

    Based on this excellent solution , if someone needs it in Kotlin :

      val tabStrip = mTabLayout.getChildAt(0) as LinearLayout
        for (i in 0..tabStrip.childCount) {
            tabStrip.getChildAt(i).setOnTouchListener(object : View.OnTouchListener{
                override fun onTouch(p0: View?, p1: MotionEvent?): Boolean {
                    return true
                }
            })
        }
    

    Or a more elegant solution with lambdas

    mTabLayout.setOnTouchListener {v: View, m: MotionEvent ->
            true
     }
    

提交回复
热议问题