关键代码,不设置的话会导致新添加的View和原来的view数据混合在一起,所以要通过父布局移除原来的view,再添加新的view。
//移除原来的customView,设置新的view
final ViewParent customParent= mTabLayout.getTabAt(0).getCustomView().getParent();if (customParent != null) {
((ViewGroup) customParent).removeView(mTabLayout.getTabAt(0).getCustomView());
}
mTabLayout.getTabAt(0).setCustomView(billFragmentAdapter.setPageTitle(0,"aaaaaaa","(11111)"));
在billFragmentAdapter里面
public View setPageTitle(int position, String title, String money){
BillTabView billTabView = (BillTabView) getTabView(position);
//BillTabView billTabView = new BillTabView(mContext);
Fragment fragment = getItem(position);
if (fragment instanceof BaseFragment) {
billTabView.setData(title,money);
}
//billTabView.updateViewLayout(billTabView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
return billTabView;
}