TabLayout选中字体大小效果(整了个TextView,赋给tab的CustomView)
为什么套了一层RelativeLayout呢,想让TextView在tab.item居中,效果好看点
切记需要tab.setCustomView(null);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
RelativeLayout rl = (RelativeLayout) LayoutInflater.from(getContext()).inflate(R.layout.textview_layout, null);
TextView textView = rl.findViewById(R.id.text_view_tab);
textView.setTextSize(18);
textView.setText(tab.getText());
tab.setCustomView(textView);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
tab.setCustomView(null);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});