Shargotth Shargotth - 1 year ago 376
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 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