Android Tablayout tabs with notification badge like whatsApp

前端 未结 9 972
感情败类
感情败类 2020-12-04 20:15

I want to implement notification badge with android.support.design.widget.TabLayout. I had tried my best effort to implement it but fails.

Any help wou

9条回答
  •  天命终不由人
    2020-12-04 20:38

    I would suggest you look at this website:

    https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout#design-support-library

    You can iterate through the different tabs using this method and set the custom views to whatever you want:

      // Iterate over all tabs and set the custom view
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            tab.setCustomView(pagerAdapter.getTabView(i));
        }
    
    public View getTabView(int position) {
        // Given you have a custom layout in `res/layout/custom_tab.xml` with a TextView and ImageView
        View v = LayoutInflater.from(context).inflate(R.layout.custom_tab, null);
        TextView tv = (TextView) v.findViewById(R.id.textView);
        tv.setText(tabTitles[position]);
        ImageView img = (ImageView) v.findViewById(R.id.imgView);
        img.setImageResource(imageResId[position]);
        return v;
    }
    
    }
    

提交回复
热议问题