AI Agent Component Spec
AI Agent Component Spec
Where It Fits
CometChatSearch is a composite search component. It searches across conversations and messages in real time and emits the selected result via setOnConversationClicked or setOnMessageClicked. Wire it to navigation so tapping a conversation opens the message view, or tapping a message scrolls to it in context.
- Kotlin
- Java
ChatActivity.kt
Quick Start
Add the component to your layout XML:activity_search.xml

CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.
To add programmatically in an Activity:
- Kotlin
- Java
SearchActivity.kt
Actions and Events
Callback Methods
setOnConversationClicked
Fires when a user taps a conversation from the search results. Primary navigation hook — set the active conversation and render the message view.
- Kotlin
- Java
SearchActivity.kt
What this does: Replaces the default conversation-click behavior. When a user taps a conversation item, your custom lambda executes. The callback receives the view, position, and Conversation object.
setOnMessageClicked
Fires when a user taps a message from the search results. Use to navigate to the message in context.
- Kotlin
- Java
SearchActivity.kt
What this does: Registers a callback that fires when the user taps a message in the search results. The callback receives the view, position, and BaseMessage object.
setOnBackPressListener
Fires when the user presses the back button in the search bar. Default: no predefined behavior.
- Kotlin
- Java
SearchActivity.kt
setOnError
Fires on internal errors (network failure, auth issue, SDK exception).
- Kotlin
- Java
SearchActivity.kt
setOnLoadMessages
Fires when the message list is successfully fetched and loaded, helping track when message search results are ready.
- Kotlin
- Java
SearchActivity.kt
setOnLoadConversations
Fires when the conversation list is successfully fetched and loaded, helping track when conversation search results are ready.
- Kotlin
- Java
SearchActivity.kt
setOnEmpty
Fires when the search returns no results, enabling custom handling such as showing a placeholder.
- Kotlin
- Java
SearchActivity.kt
- Verify: After setting an action callback, trigger the corresponding user interaction (tap a conversation result, tap a message result, press back, cause an error, or search for a term with no results) and confirm your custom logic executes.
Global UI Events
TheCometChatSearch component does not produce any global UI events.
SDK Events (Real-Time, Automatic)
TheCometChatSearch component does not listen to any SDK events internally. Search results are fetched on demand when the user types a query.
Functionality
Small functional customizations such as toggling visibility of UI elements and configuring search scope.| Methods | Description | Code |
|---|---|---|
setEmptyStateVisibility | Hides the empty state when search returns no results | .setEmptyStateVisibility(View.GONE); |
setErrorStateVisibility | Hides the error state on search failure | .setErrorStateVisibility(View.GONE); |
setSearchFilters | List of filters rendered as chips in the search component | .setSearchFilters(filters); |
setInitialSearchFilter | The filter which will be active by default on load | .setInitialSearchFilter(UIKitConstants.SearchFilter.MESSAGES); |
setSearchIn | List of entities in which the search should be performed | .setSearchIn(scopes); |
setHideGroupType | Hides the group type icon in conversation leading view | .setHideGroupType(true); |
setHideUserStatus | Hides the user’s online/offline status indicator | .setHideUserStatus(true); |
- Verify: After calling a visibility or functionality method, confirm the corresponding UI element is shown or hidden, or the search scope is correctly applied.
Custom View Slots
Each slot replaces a section of the default UI. Conversation item slots use theConversationsSearchViewHolderListener pattern (createView + bindView). Message item slots use the MessagesSearchViewHolderListener pattern.
| Slot | Method | Replaces |
|---|---|---|
| Conversation item view | setConversationItemView(ConversationsSearchViewHolderListener) | Entire conversation item row |
| Text message item | setTextMessageItemView(MessagesSearchViewHolderListener<TextMessage>) | Text message item |
| Image message item | setImageMessageItemView(MessagesSearchViewHolderListener<MediaMessage>) | Image message item |
| Audio message item | setAudioMessageItemView(MessagesSearchViewHolderListener<MediaMessage>) | Audio message item |
| Video message item | setVideoMessageItemView(MessagesSearchViewHolderListener<MediaMessage>) | Video message item |
| Document message item | setDocumentMessageItemView(MessagesSearchViewHolderListener<MediaMessage>) | Document message item |
| Link message item | setLinkMessageItemView(MessagesSearchViewHolderListener<TextMessage>) | Link message item |
| Initial view | setInitialView(@LayoutRes int) | Initial state before search |
| Empty view | setEmptyView(@LayoutRes int) | Empty state |
| Loading view | setLoadingView(View) | Loading spinner |
| Error view | setErrorView(View) | Error state |
setConversationItemView
Replace the entire conversation item row in search results.
- Kotlin
- Java
SearchActivity.kt
What this does: Registers aConversationsSearchViewHolderListenerfor conversation items in search results. ThecreateViewmethod inflates a custom layout, andbindViewpopulates it with the conversation name based on whether it’s a user or group conversation.
setTextMessageItemView
Replace the text message item view in search results.
Define a custom layout XML:
custom_message_item_view.xml
- Kotlin
- Java
SearchActivity.kt
What this does: Registers aMessagesSearchViewHolderListenerfor text messages. ThecreateViewmethod inflates the custom layout, andbindViewpopulates the sender name and message text from theTextMessageobject.

Other Message Item Views
The following message item view methods follow the sameMessagesSearchViewHolderListener pattern as setTextMessageItemView:
| Method | Message Type | Generic Type |
|---|---|---|
setImageMessageItemView | Image Message | MessagesSearchViewHolderListener<MediaMessage> |
setVideoMessageItemView | Video Message | MessagesSearchViewHolderListener<MediaMessage> |
setAudioMessageItemView | Audio Message | MessagesSearchViewHolderListener<MediaMessage> |
setDocumentMessageItemView | Document Message | MessagesSearchViewHolderListener<MediaMessage> |
setLinkMessageItemView | Link Message | MessagesSearchViewHolderListener<TextMessage> |
setInitialView
Sets a custom view displayed when the search component is rendered and no search has been performed.
- Kotlin
- Java
setEmptyView
Configures a custom view displayed when the search returns no results.
- Kotlin
- Java
setLoadingView
Sets a custom loading view displayed when search results are being fetched.
- Kotlin
- Java
setErrorView
Defines a custom error state view that appears when an issue occurs while searching.
- Kotlin
- Java
- Verify: After setting any custom view slot, confirm the custom view renders in the correct position within the search result items, and the data binding populates correctly for each result.
Common Patterns
Messages-only search
- Kotlin
- Java
Filter by message type
- Kotlin
- Java
Scope search to a specific user
- Kotlin
- Java
Scope search to a specific group
- Kotlin
- Java
Advanced Methods
Search Scope
setUid
Scopes the search to a specific user’s conversation.
- Kotlin
- Java
setGuid
Scopes the search to a specific group’s conversation.
- Kotlin
- Java
Request Builders
setConversationsRequestBuilder
Sets a ConversationsRequest.ConversationsRequestBuilder to filter conversation search results. Pass the builder instance — not the result of .build(). For all available builder options, refer to the ConversationRequestBuilder documentation.
- Kotlin
- Java
setMessagesRequestBuilder
Sets a MessagesRequest.MessagesRequestBuilder to filter message search results. For all available builder options, refer to the MessagesRequestBuilder documentation.
- Kotlin
- Java
Text Formatters
setTextFormatters
Enables developers to define and apply text formatters that dynamically modify or transform message content before rendering it in the UI. Text formatters can be used for:
- Automatically converting URLs into clickable links
- Applying Markdown or rich text styling
- Replacing certain words or patterns with emojis or predefined text
- Censoring specific words for moderation
Date/Time Formatting
setDateTimeFormatter
Provides a custom implementation of DateTimeFormatterCallback to configure how time and date values are displayed in search results.
- Kotlin
- Java
What this does: Provides a custom date/time formatter that displays “Today”, “Yesterday”, “Last Week” for recent messages, a “dd MMM yyyy” format for older messages, and relative time strings like “5 mins ago” or “2 hrs ago” for recent activity.
Other Advanced Methods
| Method | Type | Description |
|---|---|---|
setMentionAllLabelId | String id, String mentionAllLabel | Sets a custom label for the “mention all” feature for a specific ID |
setHintText | String | Sets the hint text displayed in the search bar |
Style
The component uses XML theme styles. Define a custom style with parentCometChatSearchStyle in themes.xml, then apply with setStyle().

themes.xml
What this does: Defines a custom search style that sets a light purple background color (#EDEAFA) for the search component, conversation items, and message items, and applies a Times New Roman font to all text elements including filter chips, section headers, conversation titles/subtitles, message titles/subtitles, timestamps, “see more” text, and the search bar.
- Kotlin
- Java
Programmatic Style Properties
In addition to XML theme styles, the component exposes programmatic setters for fine-grained control: Search Bar| Method | Type | Description |
|---|---|---|
setBackgroundColor | @ColorInt int | Background color of the component |
setSearchBarBackgroundColor | @ColorInt int | Background color of the search bar |
setSearchBarStrokeWidth | @Dimension int | Stroke width of the search bar border |
setSearchBarStrokeColor | @ColorInt int | Stroke color of the search bar border |
setSearchBarCornerRadius | @Dimension int | Corner radius of the search bar |
setSearchBarTextColor | @ColorInt int | Text color of the search bar input |
setSearchBarTextAppearance | @StyleRes int | Text appearance of the search bar input |
setSearchBarHintTextColor | @ColorInt int | Hint text color of the search bar |
setBackIcon | Drawable | Custom back icon drawable |
setBackIconTint | @ColorInt int | Tint color for the back icon |
setClearIcon | Drawable | Custom clear icon drawable |
setClearIconTint | @ColorInt int | Tint color for the clear icon |
setSearchIcon | Drawable | Custom search icon drawable |
setSearchIconTint | @ColorInt int | Tint color for the search icon |
| Method | Type | Description |
|---|---|---|
setFilterChipBackgroundColor | @ColorInt int | Background color of filter chips |
setFilterChipSelectedBackgroundColor | @ColorInt int | Background color of selected filter chips |
setFilterChipTextColor | @ColorInt int | Text color of filter chips |
setFilterChipSelectedTextColor | @ColorInt int | Text color of selected filter chips |
setFilterChipTextAppearance | @StyleRes int | Text appearance of filter chips |
setFilterChipStrokeColor | @ColorInt int | Stroke color of filter chips |
setFilterChipSelectedStrokeColor | @ColorInt int | Stroke color of selected filter chips |
setFilterChipStrokeWidth | @Dimension int | Stroke width of filter chips |
setFilterChipCornerRadius | @Dimension int | Corner radius of filter chips |
| Method | Type | Description |
|---|---|---|
setSectionHeaderTextColor | @ColorInt int | Text color for section headers |
setSectionHeaderTextAppearance | @StyleRes int | Text appearance for section headers |
setSectionHeaderBackgroundColor | @ColorInt int | Background color for section headers |
| Method | Type | Description |
|---|---|---|
setConversationItemBackgroundColor | @ColorInt int | Background color for conversation items |
setConversationTitleTextColor | @ColorInt int | Text color for conversation titles |
setConversationTitleTextAppearance | @StyleRes int | Text appearance for conversation titles |
setConversationSubtitleTextColor | @ColorInt int | Text color for conversation subtitles |
setConversationSubtitleTextAppearance | @StyleRes int | Text appearance for conversation subtitles |
setConversationTimestampTextColor | @ColorInt int | Text color for conversation timestamps |
setConversationTimestampTextAppearance | @StyleRes int | Text appearance for conversation timestamps |
| Method | Type | Description |
|---|---|---|
setMessageItemBackgroundColor | @ColorInt int | Background color for message items |
setMessageTitleTextColor | @ColorInt int | Text color for message titles |
setMessageTitleTextAppearance | @StyleRes int | Text appearance for message titles |
setMessageSubtitleTextColor | @ColorInt int | Text color for message subtitles |
setMessageSubtitleTextAppearance | @StyleRes int | Text appearance for message subtitles |
setMessageTimestampTextColor | @ColorInt int | Text color for message timestamps |
setMessageTimestampTextAppearance | @StyleRes int | Text appearance for message timestamps |
setMessageLinkTextColor | @ColorInt int | Text color for links in messages |
setMessageLinkTextAppearance | @StyleRes int | Text appearance for links in messages |
| Method | Type | Description |
|---|---|---|
setAvatarStyle | @StyleRes int | Style for avatars in search results |
setBadgeStyle | @StyleRes int | Style for badges in search results |
setSeeMoreTextColor | @ColorInt int | Text color for “See more” links |
setSeeMoreTextAppearance | @StyleRes int | Text appearance for “See more” links |
setDateSeparatorTextColor | @ColorInt int | Text color for date separators |
setDateSeparatorBackgroundColor | @ColorInt int | Background color for date separators |
setDateSeparatorTextAppearance | @StyleRes int | Text appearance for date separators |
setEmptyStateTextColor | @ColorInt int | Title text color for the empty state |
setEmptyStateTextAppearance | @StyleRes int | Title text appearance for the empty state |
setEmptyStateSubtitleTextColor | @ColorInt int | Subtitle text color for the empty state |
setEmptyStateSubtitleTextAppearance | @StyleRes int | Subtitle text appearance for the empty state |
setEmptyStateIcon | Drawable | Icon for the empty state |
setEmptyStateIconTint | @ColorInt int | Tint for the empty state icon |
setErrorStateTextColor | @ColorInt int | Title text color for the error state |
setErrorStateTextAppearance | @StyleRes int | Title text appearance for the error state |
setErrorStateSubtitleTextColor | @ColorInt int | Subtitle text color for the error state |
setErrorStateSubtitleTextAppearance | @StyleRes int | Subtitle text appearance for the error state |
setErrorStateIcon | Drawable | Icon for the error state |
setErrorStateIconTint | @ColorInt int | Tint for the error state icon |
Customization Matrix
| What to change | Where | Property/API | Example |
|---|---|---|---|
| Override behavior on conversation tap | Activity/Fragment | setOnConversationClicked | setOnConversationClicked { v, pos, conv -> ... } |
| Override behavior on message tap | Activity/Fragment | setOnMessageClicked | setOnMessageClicked { v, pos, msg -> ... } |
| Override back press behavior | Activity/Fragment | setOnBackPressListener | setOnBackPressListener { ... } |
| Scope search to a user | Activity/Fragment | setUid(String) | .setUid("user123") |
| Scope search to a group | Activity/Fragment | setGuid(String) | .setGuid("group123") |
| Hide user online status | Activity/Fragment | setHideUserStatus(boolean) | .setHideUserStatus(true) |
| Hide group type icon | Activity/Fragment | setHideGroupType(boolean) | .setHideGroupType(true) |
| Set search filters | Activity/Fragment | setSearchFilters(List) | .setSearchFilters(filters) |
| Set initial active filter | Activity/Fragment | setInitialSearchFilter(SearchFilter) | .setInitialSearchFilter(UIKitConstants.SearchFilter.MESSAGES) |
| Set search scope | Activity/Fragment | setSearchIn(List<SearchScope>) | .setSearchIn(scopes) |
| Filter conversation results | Activity/Fragment | setConversationsRequestBuilder | See Request Builders code above |
| Filter message results | Activity/Fragment | setMessagesRequestBuilder | See Request Builders code above |
| Custom conversation item view | Activity/Fragment | setConversationItemView(ConversationsSearchViewHolderListener) | See setConversationItemView code above |
| Custom text message item view | Activity/Fragment | setTextMessageItemView(MessagesSearchViewHolderListener) | See setTextMessageItemView code above |
| Custom image message item view | Activity/Fragment | setImageMessageItemView(MessagesSearchViewHolderListener) | See setTextMessageItemView pattern |
| Custom video message item view | Activity/Fragment | setVideoMessageItemView(MessagesSearchViewHolderListener) | See setTextMessageItemView pattern |
| Custom audio message item view | Activity/Fragment | setAudioMessageItemView(MessagesSearchViewHolderListener) | See setTextMessageItemView pattern |
| Custom document message item view | Activity/Fragment | setDocumentMessageItemView(MessagesSearchViewHolderListener) | See setTextMessageItemView pattern |
| Custom link message item view | Activity/Fragment | setLinkMessageItemView(MessagesSearchViewHolderListener) | See setTextMessageItemView pattern |
| Custom initial view | Activity/Fragment | setInitialView(@LayoutRes int) | .setInitialView(R.layout.your_initial_view) |
| Custom loading view | Activity/Fragment | setLoadingView(View) | .setLoadingView(loadingView) |
| Custom empty view | Activity/Fragment | setEmptyView(@LayoutRes int) | .setEmptyView(R.layout.your_empty_view) |
| Custom error view | Activity/Fragment | setErrorView(View) | .setErrorView(errorView) |
| Empty state visibility | Activity/Fragment | setEmptyStateVisibility(int) | .setEmptyStateVisibility(View.GONE) |
| Error state visibility | Activity/Fragment | setErrorStateVisibility(int) | .setErrorStateVisibility(View.GONE) |
| Change colors, fonts, spacing | themes.xml | CometChatSearchStyle | <item name="cometchatSearchBackgroundColor">#EDEAFA</item> |
| Apply a custom style | Activity/Fragment | setStyle(int styleRes) | binding.cometchatSearch.setStyle(R.style.CustomSearchStyle) |
| Search bar background | Activity/Fragment | setSearchBarBackgroundColor | .setSearchBarBackgroundColor(color) |
| Filter chip colors | Activity/Fragment | setFilterChip* methods | .setFilterChipBackgroundColor(color) |
| Section header style | Activity/Fragment | setSectionHeader* methods | .setSectionHeaderTextColor(color) |
| Conversation item style | Activity/Fragment | setConversation* methods | .setConversationTitleTextColor(color) |
| Message item style | Activity/Fragment | setMessage* methods | .setMessageTitleTextColor(color) |
| Date/time formatting | Activity/Fragment | setDateTimeFormatter(DateTimeFormatterCallback) | See setDateTimeFormatter code above |
| Text formatters | Activity/Fragment | setTextFormatters(List) | See Text Formatters section |
| Search bar hint text | Activity/Fragment | setHintText(String) | .setHintText("Search...") |
| Mention-all label | Activity/Fragment | setMentionAllLabelId(String, String) | .setMentionAllLabelId(id, label) |
| Callback on messages loaded | Activity/Fragment | setOnLoadMessages(OnLoad<BaseMessage>) | .setOnLoadMessages { list -> ... } |
| Callback on conversations loaded | Activity/Fragment | setOnLoadConversations(OnLoad<Conversation>) | .setOnLoadConversations { list -> ... } |
Accessibility
The component renders a search bar with filter chips and scrollable result lists for conversations and messages. The search input is focusable and supports keyboard input. Filter chips respond to tap gestures and announce their selected state. For custom views provided viasetConversationItemView or message item view setters, ensure you set android:contentDescription on visual-only elements so TalkBack can announce them. The default views handle this automatically.