app:tabIndicatorFullWidth="false"
app:tabPaddingStart="0dp"
app:tabPaddingEnd="0dp"
app:tabUnboundedRipple="@null"
这些属性比较重要
接下来是代码片段
ColorStateList colorStateList = tabs.getTabTextColors();
TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(tabs, viewPager, (tab, position) -> {
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_tab,tab.parent,false); TextView month = view.findViewById(R.id.tv_month);
TextView day = view.findViewById(R.id.tv_day);
String str1 = dateList.get(position).getName().substring(0,3);
month.setText(str1);
String str2 = dateList.get(position).getName().substring(3); if(toDay.equals(dateList.get(position).getType())){
day.setText("今天");
}else {
day.setText(str2);
}
month.setTextColor(colorStateList);
day.setTextColor(colorStateList);
tab.setCustomView(view);
}
);
//这句话很重要
tabLayoutMediator.attach();