Skip to main content
Version: v4

Contacts

CometChatContacts is a versatile Android UI component specifically designed to facilitate the display and management of users and groups within chat applications. It streamlines the process of showcasing all app users and available chat groups in a user-friendly interface, making it easier for users to connect and communicate effectively.

Key Features:

  1. User List View: CometChatContacts presents a comprehensive list of all registered users within the application. This list allows users to quickly find and select specific individuals they wish to interact with.
  2. Group List View: The component also offers a dedicated view to showcase all the available chat groups. This simplifies the process of joining or creating new group conversations.
  3. Smart Search Functionality: Users can utilize the powerful search feature to quickly locate specific users or groups by typing names or keywords. This ensures seamless navigation, even in applications with a large user base.
  4. Selection Mode: CometChatContacts supports a selection mode, enabling users to pick multiple contacts or groups simultaneously. This feature proves useful for creating group chats or forwarding messages to multiple recipients.
  5. Customizable Tab Layout: Developers can easily customize the appearance of the tabs, including text colors, indicator color, and background, to match the app's branding and aesthetics.
  6. Selection Limit Control: Developers have the flexibility to set a selection limit, restricting the number of contacts or groups a user can select during the selection mode. This helps maintain messaging policies and optimize user experience.
  7. User-Friendly Close Button: The component provides a convenient close button feature, allowing users to exit the Contacts view and return to their previous screen or chat interface effortlessly.

How to integrate CometChatContacts

since CometChatContacts is a Widget, it can be added directly to the layout file as shown below.

<com.cometchat.chatuikit.contacts.CometChatContacts
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contacts"/>

Methods

MethodsParametersDescription
setTitle(String title)StringSets the title that will be displayed at the top of the CometChatContacts view. This method allows you to customize the title to provide relevant information or context to the users.
setCloseButtonIcon(@DrawableRes int closeButtonIcon)@DrawableRes intSets the icon that will be displayed as the close button in the CometChatContacts view.
setCloseButtonVisibility(boolean showBackButton)booleanSets the visibility of the back button in the CometChatContacts view. If set to true, the back button will be displayed, allowing users to navigate back to the previous screen. If set to false, the back button will be hidden.
setSubmitIcon(@DrawableRes int submitIcon)@DrawableRes intSets the icon that will be displayed as the submit icon in the CometChatContacts view.
setSubmitIconVisibility(int value)intSets the visibility of the submit icon in the CometChatContacts view. If set to View.VISIBLE, the submit icon will be visible, allowing users to submit their selections. If set to View.GONE, the submit icon will be hidden.
setOnSubmitIconClick(OnSelection onSelection)OnSelectionSets the listener that will be triggered when the submit icon is clicked in the CometChatContacts view. The listener can be used to handle Contacts selection events, allowing users to perform actions based on the selected users and groups.
setStyle(ContactsStyle style)ContactsStyleSets various style configurations for the CometChatContacts view, including title appearance, font, color, background, border, tab colors, and more.
setSelectionLimit(int limit)intSets the selection limit for the CometChatContacts view. This method allows you to limit the number of users and groups that can be selected by the user in the Contacts view. Once the selection limit is reached, further selection of users and groups will be disabled.
setSelectionMode(UIKitConstants.SelectionMode selectionMode)UIKitConstants.SelectionModeselectionMode is used to set the selection mode for the CometChatUsers and CometChatGroups subviews embedded inside CometChatContacts.
setUsersTabTitle(String title)StringSets the title for the Users tab in the CometChatContacts view. This method allows you to customize the title displayed for the Users tab.
setGroupsTabTitle(String title)StringSets the title for the Groups tab in the CometChatContacts view. This method allows you to customize the title displayed for the Groups tab.
setOnItemClickListener(OnItemSelection selection)OnItemSelectionSets the listener to handle item selection events in the CometChatContacts view. This method allows you to register a callback to be notified when a user or group is selected by the user in the Contacts view.
setUsersConfiguration(UsersConfiguration configuration)UsersConfigurationSets the configuration for the Users tab in the CometChatContacts view. This method allows you to customize various aspects of the Users tab, such as search functionality, appearance and more. By passing a valid UsersConfiguration object, you can control how the Users tab behaves and appears to the users.
setGroupsConfiguration(GroupsConfiguration configuration)GroupsConfigurationSets the configuration for the Groups tab in the CometChatContacts view. This method allows you to customize various aspects of the Groups tab, such as search functionality, appearance and more. By passing a valid GroupsConfiguration object, you can control how the Groups tab behaves and appears to the users.

ContactsStyle

This property is used to customize the appearance of the CometChatContacts component.

MethodsParameterDescription
setBackground(int background)@ColorInt intSets the background color of the view.
setBackground(Drawable drawableBackground)DrawableSets the drawable background of the view.
setCornerRadius(float cornerRadius)floatSets the corner radius of the view.
setBorderWidth(int borderWidth)@ColorInt intSets the width of the view's border.
setBorderColor(int borderColor)@ColorInt intSets the color of the view's border.
setTitleTextColor(int titleTextColor)@ColorInt intSets the title text color for the contacts-related UI elements.
setBackIconTintColor(int backIconTintColor)@ColorInt intSets the tint color for the back icon.
setSelectIconTint(int selectIconTint)@ColorInt intSets the tint color for the select icon.
setTabSelectedTextColor(int tabSelectedTextColor)@ColorInt intSets the text color for the selected tab.
setTabTextColor(int tabTextColor)@ColorInt intSets the text color for the tabs.
setTabIndicatorColor(int tabIndicatorColor)@ColorInt intSets the color for the tab indicator.
setTabBackgroundTint(int tabBackgroundTint)@ColorInt intSets the tint color for the tab background.
setTabBackground(Drawable tabBackground)DrawableSets the drawable resource for the tab background.
setTabBackgroundState(Drawable tabBackgroundState)DrawableSets the drawable resource for the tab background state.
setTitleTextFont(String titleTextFont)StringSets the font for the title text.
setTitleTextAppearance(@StyleRes int titleTextAppearance)@ColorInt intSets the text appearance for the title text.
// Create an instance of ContactsStyle
ContactsStyle contactsStyle = new ContactsStyle();

// Customize the appearance of UI elements
contactsStyle.setBackground(ContextCompat.getColor(context, R.color.contacts_background));
contactsStyle.setTitleTextColor(ContextCompat.getColor(context, R.color.contacts_title_text));
contactsStyle.setBackIconTintColor(ContextCompat.getColor(context, R.color.contacts_back_icon_tint));
contactsStyle.setSelectIconTint(ContextCompat.getColor(context, R.color.contacts_select_icon_tint));
contactsStyle.setTabSelectedTextColor(ContextCompat.getColor(context, R.color.contacts_tab_selected_text));
contactsStyle.setTabTextColor(ContextCompat.getColor(context, R.color.contacts_tab_text));
contactsStyle.setTabIndicatorColor(ContextCompat.getColor(context, R.color.contacts_tab_indicator));
contactsStyle.setTabBackgroundTint(ContextCompat.getColor(context, R.color.contacts_tab_background_tint));
contactsStyle.setTabBackground(ResourcesCompat.getDrawable(resources, R.drawable.contacts_tab_background, null));
contactsStyle.setTabBackgroundState(ResourcesCompat.getDrawable(resources, R.drawable.contacts_tab_background_state, null));
contactsStyle.setTitleTextFont("fonts/Roboto-Regular.ttf");
contactsStyle.setTitleTextAppearance(R.style.ContactsTitleTextAppearance);

// Now, you can use the contactsStyle object to customize the appearance of UI elements related to contacts in your chat application
CometChatContacts contacts=findViewById(R.id.contacts);
contacts.setStyle(contactsStyle);