public View getTabView(Context context, int position) {
int[] unreadCount = {3, 1, 2};
View tab = LayoutInflater.from(context).inflate(R.layout.partial_custom_tab, null);
tabText = (TextView) tab.findViewById(R.id.tab_title);
counter = (View) tab.findViewById(R.id.tab_badge);
tabText.setText(mPages.get(position).title);
if (mPages.get(position).icon != null) {
counter.setVisibility(View.VISIBLE);
counter.setBackground(mPages.get(position).icon);
} else {
counter.setVisibility(View.GONE);
}
BadgeDrawable badge = new BadgeDrawable(getContext(),
getResources().getColor(R.color.colorAccent));
if (unreadCount[position] > 0) {
counter.setVisibility(View.VISIBLE);
badge.setCount(unreadCount[position]);
badge.mutate();
counter.setBackground(badge);
} else {
counter.setVisibility(View.GONE);
}
if (position == 0) {
tab.setSelected(true);
}
return tab;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句