Skip to main content
Version: v4

Badge

CometChatBadge is the custom component which is used to display the unread message count. It can be used in places like CometChatListItem, etc.

Image

How to integrate CometChatBadgeCount ?

Since CometChatBadge is a custom view, it can be added directly in the layout file or you can use it in Java. CometChatBadge includes various attributes and methods to customize its UI.

Usage in XML

<com.cometchat.chatuikit.shared.views.CometChatBadge.CometChatBadge
android:id="@+id/badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

XML Attributes

ParametersDescription
app:count_background_colorUsed to set the backgroundColor
app:strokeWidthUsed to set the borderWidth
app:countUsed to set value of count.
app:count_colorUsed to set color of count value.
app:count_sizeUsed to set text size of count value
<com.cometchat.chatuikit.shared.views.CometChatBadge.CometChatBadge
android:layout_gravity="center"
android:layout_width="wrap_content"
app:count="1"
app:count_background_color="@color/colorPrimaryDark"
app:count_color="@color/light_grey"
android:id="@+id/badge"
android:layout_height="wrap_content"/>

Methods

Customization

This Methods are use to do modify the appearance of CometChatBadge

MethodsDescription
cornerRadius(float radius)Used to set the cornerRadius
borderColor(@ColorInt int color)Used to set the borderColor
setBackground(@ColorInt int color)Used to set the backgroundColor
borderWidth(int width)Used to set the borderWidth
setCount(int counValue)Used to set value of count.
setTextColor(@ColorInt int color)Used to set color of count value(TextView)
setTextSize(float size)Used to set text size of count value
CometChatBadge badge = findViewById(R.id.badge);
//syntax for cornerRadius(float radius)
badge.cornerRadius(18);

//syntax for borderColor(@ColorInt int color)
badge.borderColor(getResources().getDrawable(R.drawable.stroke_color));

//syntax for setBackground(@ColorInt int color)
badge.setBackground(getResources().getDrawable(R.drawable.background));

//syntax for borderWidth(int width)
badge.borderWidth(1);

//syntax for setCount(int counValue)
badge.setCount(12);

//syntax for setTextColor(@ColorInt int color)
badge.setTextColor(getResources().getDrawable(R.drawable.count_color));

//syntax for setTextSize(float size)
badge.setTextSize(10);