2017-10-17 11 views
0

지금은 뷰 페이저로 작업하는 간단한 탭 레이아웃 만 있습니다. 내 탭 레이아웃을 커스터마이징하는 방법을 알고 싶습니다. 예를 들어, 내 뷰어 호출기의 해당 조각에 대한 리사이클 러 뷰의 아이템 수를 앱에 표시하는 기능이 필요합니다. 감사Whatsapp와 같은 탭 레이아웃의 카운터를 만드는 방법은 무엇입니까?

This is an example

+0

탭 제목에 스팬을 사용할 수 있습니까? 그렇다면 어딘가 시작할 수 있습니다. – stkent

답변

1
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; 
} 
0

당신은 같은 것을 할 수 있습니다 : 그것은

LinearLaout tabone= (LinearLaout) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); 

TextView txtView= (TextView) tabone.findViewById(R.id.txtview); 
txtView.setText("ONE"); 

TextView txtCount= (ImageView) tabone.findViewById(R.id.txtcount); 
txtCount.setText("200")//Count 
/*Also don't forgot to add background of count textview in xml according to your design.*/ 

tabLayout.getTabAt(0).setCustomView(tabone); 

입니다!