Shargotth Shargotth - 2 years ago 265
Android Question

Disable TabLayout

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 disable swipe on its viewpager but I can't figure out how to disable the change of page by clicking on tabs.

Thank's in advance.

Answer Source

I had the same problem and I solved it disabling touch event on tabs with the following code:

  LinearLayout tabStrip = ((LinearLayout)mTabLayout.getChildAt(0));
    for(int i = 0; i < tabStrip.getChildCount(); i++) {
        tabStrip.getChildAt(i).setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                return true;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download