Skip to main content
Version: v4

Avatar

CometChatAvatar component displays an image or user's avatar with fallback to the first two letters of the username or group's icon with fallback to the first two letter of the group name.

Image

How to integrate CometChatAvatar ?

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

Usage in XML

<com.cometchat.chatuikit.shared.views.CometChatAvatar.CometChatAvatar
android:id="@+id/item_avatar"
android:layout_width="40dp"
android:layout_height="40dp"
/>

XML Attributes

ParametersDescription
app:corner_radius="18dp"Used to set the cornerRadius
app:border_color="@color/red"Used to set the borderColor
app:background_color="@color/blue"Used to set the backgroundColor
app:border_width="5dp"Used to set the borderWidth
<com.cometchat.chatuikit.shared.views.CometChatAvatar.CometChatAvatar
android:id="@+id/avataricon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center" tools:src="@tools:sample/avatars"/>

Methods

MethodsTypeDescription
setImageStringImage will be obtained from path from assets. if name and image both are passed image will be visible
**setName**StringUsed to can specify name to be shown in avatar (initials only), if image is not available
setStyleAvatarStyleUsed to customize appearance of the Avatar

AvatarStyle

MethodsTypeDescription
setHeightdoubleused to set height
setWidthdoubleused to set width
setBorderWidthBoxBorderused to set border of the inner circle
setBackgroundColorused to set background color
setBackgroundGradientused to set a gradient background
setCornerRadiusdoubleused to modify the corner radius of inner circle
setOuterCornerRadiusdoubleused to modify the corner radius of outer circle
setOuterBorderWidthBoxBorderused to modify the border of outer circle
setInnerViewWidthdoubleused to modify the border width of outer circle
setOuterBackgroundColorColorused to modify the background color of outer circle
setOuterViewSpacingdoubleused to modify spacing between the image and the outer border
setTextAppearanceTextStyleused to modify the text style for name if image is not available
AvatarStyle avatarStyle =  new AvatarStyle();
avatarStyle.setInnerViewBorderColor(getResources().getColor(android.R.color.holo_red_dark));
avatarStyle.setInnerViewRadius(100);
avatarStyle.setOuterBorderWidth(10);
avatarStyle.setInnerViewWidth(10);
avatarStyle.setOuterBorderColor(getResources().getColor(android.R.color.black));

CometChatAvatar avatar=view.findViewById(R.id.item_avatar);
avatar.setStyle(avatarStyle);
Image