2017-07-26 63 views
0

我已经查看了所有的round stackoverflow如何在标签布局中的标签图标中添加徽章,但没有答案。在使用badgeView的Tablayout中的标签图标上添加徽章

这是我的代码

//Get reference to your Tablayout 
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 
    tabLayout.setupWithViewPager(mViewPager); 
    tabLayout.getTabAt(0).setIcon(ICONS[0]); 
    tabLayout.getTabAt(1).setIcon(ICONS[1]); 
    tabLayout.getTabAt(2).setIcon(ICONS[2]); 

    BadgeView badge = new BadgeView(this, tabLayout.getTabAt(0).getCustomView()); 
    badge.setText("1"); //Whatever value you should add 
    badge.show(); 


    BadgeView mMotification = new BadgeView(this, tabLayout.getChildAt(1)); 
    mMotification.setText("10"); 
    mMotification.show(); 

我也尝试过很多其他的替代品,但它似乎像BadgeView只需意见

回答

0

可以为标签创建自定义布局和TabLayout

0
添加它们

这就是我所做的工作

TabLayout.Tab tab = tabLayout.getTabAt(0); 
    ImageView imageView = new ImageView(this); 
    imageView.setImageResource(R.drawable.ic_notifications); 

    tab.setCustomView(imageView); 
    BadgeView badge = new BadgeView(this, imageView); 
    badge.setText("23"); 
    badge.setBadgeMargin(25,0); 
    badge.show();