Shargotth Shargotth - 5 months ago 81
Android Question

android disable TabLayout

I'm using the new class provided by the design library : TabLayout. and I want in specific case that the one I'm using can't change tab anymore.

I manage to disable swipe on his viewpager but I can't figured out how to disable the change of page by clicking on tabs.

Thank's in advance.

Answer

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() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }
Comments