Abhijith Surendran
Abhijith Surendran

Reputation: 41

Disable multi touch for tabs in TabLayout

I have used android.support.design.widget.TabLayout in my app and have added 4 tabs to it. I am able to click on all the tabs even when i had already kept one of them pressed. I am wondering how i can prevent the other tabs from being clickable when any one of the tabs is already pressed. i had already tried setting split motion events to false and using touchevent method, but it didn't work. Thanks in advance.

Upvotes: 3

Views: 1025

Answers (1)

Jeremy Dowdall
Jeremy Dowdall

Reputation: 1274

You need to set split motion events to false on the child container inside the TabLayout, not on the TabLayout itself. Something like this:

((ViewGroup) tabLayout.getChildAt(0)).setMotionEventSplittingEnabled(false);

Setting split motion events to false will only block multitouch from the immediate children of the ViewGroup it is set upon. TabLayout extends HorizontalScrollView and therefore contains a single child ViewGroup which, in turn, contains the actual tabs that receive the click events to be blocked.

Upvotes: 4

Related Questions