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
If you are using a custom view for the Tab, you can use View#getParent() to get a reference to the Tab's View if you don't want to look through the ViewGroups.
Note: Using the custom view itself instead of the parent may not work because it can have margin, allowing the user to click in the empty space and change the tab still.
View tabView = (View) tab.getCustomView().getParent();
tabView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
//or
tabView.setEnabled(false);
The OnTouchListener way and the setEnabled() way do different things, but have the same effect. I prefer the one-liner.
Again, this only works if you use a custom view, otherwise the getParent() call will cause a NullPointerException.