Disable TabLayout

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

    For me the working approach is this:

    bool condition = ...
    foreach (var view in _tabLayout.Touchables)
        view.Clickable = condition;
    

    This is 100% safe, as getTouchables() call is supported since API 1. No need to manually traverse layout or something. I consider it to be much simpler than that of the accepted answer, but only when all the tabs have to be marked not clickable.

    P.S.: example is on C#, as I am working with Xamarin, but it is fairly easy to translate it back to Java. Enjoy! =)

    Kotlin example:

    tabLayout.touchables.forEach { it.isClickable = false }
    

    Java example:

    for (View v: tabLayout.getTouchables())
        v.setClickable(false);
    

提交回复
热议问题