GitHub control-BadgeView (Digital Reminder), githubbadgeview
The number reminds everyone to have seen it. QQ, and so on, if there is a message or reminder in the app, the user will be given a red dot or a digital dot. Some time ago, I switched my avatar to an avatar with a digital reminder, which made those with obsessive-compulsive disorder crazy.
Next, let's take a look at how to implement this effect in our app.
Developers can certainly achieve this by themselves using relative layout. It's okay, but it's too much! It will be complicated. GitHub has an open-source third-party control called BadgeView. You can use it to achieve the desired effect.
How to use it first, a simple three-line code can implement a digital reminder:
BadgeView badgeView = new com.jauker.widget.BadgeView(this);badgeView.setTargetView(textView);badgeView.setBadgeCount(3);
Take a look at the common methods in badgeview:
1. setTargetView (View) --> sets the control to display a digital reminder. The parameter is a view object.
2. setBadgeCount (int) --> set the number of the reminder
3. setBadgeGravity (Gravity) --> set the position of the badgeview
4. setBackgroundColor () --> set the background color of badgeview. You can also set the background image.
5. setBackgroundResource () --> set the background image
6. setTypeface () --> set the font to display
7. setShadowLayer () --> set the font shadow.
BadgeView = new BadgeView (this); badgeView. setTargetView (layout); badgeView. setBackground (12, Color. parseColor ("# 9b2eef"); badgeView. setText ("prompt ");
badgeView = new BadgeView(this);badgeView.setTargetView(layout);badgeView.setBadgeGravity(Gravity.BOTTOM | Gravity.CENTER);badgeView.setBadgeCount(4);
badgeView = new BadgeView(this);badgeView.setTargetView(layout);badgeView.setBadgeGravity(Gravity.TOP | Gravity.LEFT);badgeView.setTypeface(Typeface.create(Typeface.SANS_SERIF,Typeface.ITALIC));badgeView.setShadowLayer(2, -1, -1, Color.GREEN);badgeView.setBadgeCount(2);
In fact, the BadgeView class inherits TextView. Many methods for setting fonts in TextView apply to BadgeView.
OK. The effect is completed.
BadgeView download link
Download badgeview. jar
Download DEMO