Display a badgeView on any view with RealTime Update.
Step.1 Library implementation: Add This Line To your build.gradle (lastest v1.0.9):
dependencies {implementation 'com.github.karim-eg:Smart-BadgeView:1.0.9' }Step.2 Create Private Variable: private BadgeView badgeView ;if you're using ide that didn't support auto import add these lines: import com .enceptcode .badgeview .BadgeFactory ;import com .enceptcode .badgeview .BadgeView ;Step.3 Add This Line atonCreate
: badgeView =BadgeFactory .createCircle (MainActivity .this );You Can ReplacecreateCircle()
property with:createDot()
,createRectangle()
,createOval()
,createSquare()
,createRoundRect()
private void updateBadge (final String count ,final ImageView image ) {badgeView .setBadgeCount (count ).setSpace (5 ,3 ).setTextSize (10 ).bind (image );}you can add or change any property to other available methods: .setTextColor(Color.White)
.setWidthAndHeight(25,25)
.setBadgeBackground(Color.Red)
.setTextSize(10)
.setBadgeGravity(Gravity.Right|Gravity.Top)
.setShape(BadgeView.SHAPE_CIRCLE)
finally add this line atonResume
oronCreate
to call the void you had created before and display badge.
updateBadge ("21" ,imageview3 );void have two parameters first is the badge count, second is the view that badge will display on it.
to unbind view just useunbind
method: Apache License