Disable Click On Tablayout, When Setup With Viewpager
I have a ViewPager (3 items) with some icons. When on first item, the icon is selected, there is possible to swipe to the next item. Etc. After selected second icon, there is possi
Solution 1:
try this for api >24:
tabLayout.clearOnTabSelectedListeners();
or for <24:
tabLayout.setupWithViewPager(viewPager);
LinearLayouttabStrip= ((LinearLayout)tabLayout.getChildAt(0));
for(inti=0; i < tabStrip.getChildCount(); i++) {
tabStrip.getChildAt(i).setOnTouchListener(newView.OnTouchListener() {
@OverridepublicbooleanonTouch(View v, MotionEvent event) {
returntrue;
}
});
}
Solution 2:
You can extend the TabLayout class and override the method 'setupWithViewPager'. You need to call the super method to populate the tabs. Then this will iterate with the tabs and disable clicks:
@OverridepublicvoidsetupWithViewPager(@Nullable ViewPager viewPager) {
super.setupWithViewPager(viewPager);
for (inti=0; i < getTabCount(); i++) {
Tabtab= getTabAt(i);
if (tab != null) {
tab.view.setClickable(false);
}
}
}
Post a Comment for "Disable Click On Tablayout, When Setup With Viewpager"