How can I disable click on TabLayout in Android
You are accessing tabs before setupWithViewPager, thats why your code is not working. So first set tabs then settouchlistener code.
Try this:
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();
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;
}
});
}
For ViewPager2 (minimum v1.1.0) you can accomplish this in the TabLayoutMediator
.
new TabLayoutMediator(tabLayout, pager,
(tab, position) -> {
tab.view.setClickable(false);
}
).attach();
And in build.gradle
:
com.google.android.material:material:1.1.0-rc02