AlexLiuSheng / BadgeView

a BadeView base on android
730 stars 109 forks source link

Bind to TabLayout #14

Open zishanj opened 5 years ago

zishanj commented 5 years ago

Can I bind to text or icon in TabLayout?

AlexLiuSheng commented 5 years ago

yes,you can, but we should understand badge need bind to a view .So you may do like following

 TabLayout.Tab tab = tabLayout.getTabAt(i);
View customView=inflater.inflate();//inflate your custom view
BadgeView badgeView=BadgeFactory.create(getActivity())
                .setBadgeCount("1")
                .setShape(BadgeView.SHAPE_CIRCLE)
                .setWidth(16)
                .setHeight(16)
                .setSpace(6, 6)
                .setTextColor(Color.WHITE)
                .setBadgeBackground(ContextCompat.getColor(getContext(), R.color.pastel_red))
                .setTextSize(11)
                .bind(customView);
tab.setCustomView(customView);
zishanj commented 5 years ago

Can the width and height be adjusted automatically based on the count value? If the counter value is bigger it should auto adjust its width.

zishanj commented 5 years ago

I have tried your code but it does not attach to the view and does not show. No error reported though!