If you need to click a tab, and not every time a tab is selected, you can use a custom view for each tab, and then process a click on the corresponding view, for example, like this:
for (int i = 0; i < tabLayout.getTabCount(); i++) {
final TabLayout.Tab tab = tabLayout.getTabAt(i);
final View tabView = LayoutInflater.from(this).inflate(
R.layout.item_tab, (ViewGroup) tab.getCustomView(), false);
tabLayout.setCustomView(tabView);
final TextView customView = (TextView) tab.getCustomView();
customView.setText(mAdapter.getPageTitle(i));
final int index = i;
customView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tabLayout.getSelectedTabPosition() == index) {
} else {
tab.select();
}
}
});
}
source
share