AI Agent Component Spec
AI Agent Component Spec
Where It Fits
CometChatThreadHeader is a header component for threaded message views. It renders the parent message bubble and reply count. Wire it above a CometChatMessageList and CometChatMessageComposer to build a complete threaded conversation layout.
- Kotlin
- Java
ThreadActivity.kt
Quick Start
Add the component to your layout XML:layout_activity.xml

CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.
Set the parent message in your Activity:
- Kotlin
- Java
YourActivity.kt
- Kotlin
- Java
YourFragment.kt
Actions and Events
Callback Methods
CometChatThreadHeader does not expose component-specific callback methods like setOnItemClick or setOnError. It is a display-only header that renders the parent message and reply count.
Global UI Events (CometChatMessageEvents)
CometChatThreadHeader does not emit its own global UI events. The parent message updates are handled internally via the ThreadHeaderViewModel, which listens for message edits, deletes, and reaction changes on the parent message.
SDK Events (Real-Time, Automatic)
The component listens to SDK events internally via its ViewModel. No manual attachment needed.| SDK Listener | Internal behavior |
|---|---|
| Message edited | Updates the parent message bubble if the parent message is edited |
| Message deleted | Updates the parent message bubble if the parent message is deleted |
| Reply count changed | Updates the reply count indicator when new replies are added |
Automatic: parent message changes and reply count updates reflect in real time.
Functionality
Small functional customizations such as toggling visibility of UI elements and configuring alignment.| Method | Description | Code |
|---|---|---|
setReactionVisibility | Shows or hides reactions on the parent message bubble | .setReactionVisibility(View.GONE) |
setAvatarVisibility | Shows or hides the avatar in the thread header | .setAvatarVisibility(View.GONE) |
setReceiptsVisibility | Shows or hides read receipts on the parent message bubble | .setReceiptsVisibility(View.GONE) |
setReplyCountVisibility | Shows or hides the reply count text | .setReplyCountVisibility(View.GONE) |
setReplyCountBarVisibility | Shows or hides the reply count bar/layout | .setReplyCountBarVisibility(View.GONE) |
setMaxHeight | Sets the maximum height limit for the thread header in pixels | .setMaxHeight(500) |
setAlignment | Sets bubble alignment: STANDARD (left/right by message type) or LEFT_ALIGNED (all left) | .setAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED) |
- Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden.
Custom View Slots
CometChatThreadHeader does not use the traditional ViewHolderListener pattern for view slots. Instead, it uses CometChatMessageTemplate to customize how the parent message bubble is rendered.
setTemplates
Replaces the default list of message templates used to render the parent message bubble.
- Kotlin
- Java
What this does: Replaces the entire set of message templates. The parent message bubble renders using the custom template configuration. If you pass an empty list, no message bubble renders.
addTemplate
Adds a single message template to the existing list without replacing defaults.
- Kotlin
- Java
What this does: Appends a new CometChatMessageTemplate to the existing template list. Use this when you want to support an additional message type without removing the built-in templates.
- Verify: After calling
setTemplatesoraddTemplate, confirm the parent message bubble renders using the custom template configuration.
Common Patterns
Hide reactions on the parent message
- Kotlin
- Java
Left-align all message bubbles
- Kotlin
- Java
Custom time format
- Kotlin
- Java
Hide reply count and reply count bar
- Kotlin
- Java
Advanced Methods
setParentMessage
Sets the parent message for the thread header. This is required — the component will not render without it.
- Kotlin
- Java
setTemplates
Replaces the default list of message templates used to render the parent message bubble.
- Kotlin
- Java
addTemplate
Adds a single message template to the existing list.
- Kotlin
- Java
setTextFormatters
Adds custom text formatters to the current list of formatters used in the thread header.
- Kotlin
- Java
setTimeFormat
Sets a custom time format for the parent message display.
- Kotlin
- Java
setAlignment
Sets the bubble alignment for the parent message.
- Kotlin
- Java
InSTANDARDmode, the bubble appears on the left or right based on whether the message is incoming or outgoing. InLEFT_ALIGNEDmode, all bubbles appear on the left.
Internal Access
These methods provide direct access to internal components for advanced use cases.| Method | Returns | Description |
|---|---|---|
getRecyclerView() | RecyclerView | The RecyclerView used for the parent message bubble |
getBinding() | CometchatThreadHeaderBinding | The ViewBinding for the component’s root layout |
getThreadedHeaderViewModel() | ThreadHeaderViewModel | The ViewModel managing thread header state |
getAdapter() | MessageAdapter | The adapter powering the parent message RecyclerView |
Bubble Style Methods
| Method | Type | Description |
|---|---|---|
setIncomingMessageBubbleStyle | @StyleRes int | Sets the style for incoming message bubbles |
setOutgoingMessageBubbleStyle | @StyleRes int | Sets the style for outgoing message bubbles |
Use internal access methods only when the standard API is insufficient. Directly manipulating the adapter or ViewModel may conflict with the component’s internal state management.
Style
The component uses XML theme styles. Define a custom style with parentCometChatThreadHeaderStyle in themes.xml, then apply with setStyle().

themes.xml
- Kotlin
- Java
Programmatic Style Properties
In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:| Method | Type | Description |
|---|---|---|
setReplyCountBackgroundColor | @ColorInt int | Background color of the reply count view |
setReplyCountTextColor | @ColorInt int | Text color of the reply count view |
setReplyCountTextAppearance | @StyleRes int | Text appearance of the reply count view |
setIncomingMessageBubbleStyle | @StyleRes int | Style for incoming message bubbles |
setOutgoingMessageBubbleStyle | @StyleRes int | Style for outgoing message bubbles |
Customization Matrix
| What to change | Where | Property/API | Example |
|---|---|---|---|
| Parent message | Activity/Fragment | setParentMessage(BaseMessage) | threadHeader.setParentMessage(baseMessage) |
| Reaction visibility | Activity/Fragment | setReactionVisibility(int) | .setReactionVisibility(View.GONE) |
| Avatar visibility | Activity/Fragment | setAvatarVisibility(int) | .setAvatarVisibility(View.GONE) |
| Receipt visibility | Activity/Fragment | setReceiptsVisibility(int) | .setReceiptsVisibility(View.GONE) |
| Reply count visibility | Activity/Fragment | setReplyCountVisibility(int) | .setReplyCountVisibility(View.GONE) |
| Reply count bar visibility | Activity/Fragment | setReplyCountBarVisibility(int) | .setReplyCountBarVisibility(View.GONE) |
| Max height | Activity/Fragment | setMaxHeight(int) | .setMaxHeight(500) |
| Bubble alignment | Activity/Fragment | setAlignment(MessageListAlignment) | .setAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED) |
| Time format | Activity/Fragment | setTimeFormat(SimpleDateFormat) | .setTimeFormat(new SimpleDateFormat("hh:mm a", Locale.getDefault())) |
| Text formatters | Activity/Fragment | setTextFormatters(List) | .setTextFormatters(formatterList) |
| Message templates (replace) | Activity/Fragment | setTemplates(List<CometChatMessageTemplate>) | .setTemplates(templateList) |
| Message templates (add) | Activity/Fragment | addTemplate(CometChatMessageTemplate) | .addTemplate(template) |
| Outgoing bubble style | themes.xml | cometchatThreadHeaderOutgoingMessageBubbleStyle | <item name="cometchatThreadHeaderOutgoingMessageBubbleStyle">@style/CustomOutgoingStyle</item> |
| Incoming bubble style | themes.xml | cometchatThreadHeaderIncomingMessageBubbleStyle | <item name="cometchatThreadHeaderIncomingMessageBubbleStyle">@style/CustomIncomingStyle</item> |
| Header background color | themes.xml | cometchatThreadHeaderBackgroundColor | <item name="cometchatThreadHeaderBackgroundColor">#FEEDE1</item> |
| Reply count text color | themes.xml | cometchatThreadHeaderReplyCountTextColor | <item name="cometchatThreadHeaderReplyCountTextColor">#F76808</item> |
| Reply count background color | themes.xml | cometchatThreadHeaderReplyCountBackgroundColor | <item name="cometchatThreadHeaderReplyCountBackgroundColor">#FEEDE1</item> |
| Apply a custom style | Activity/Fragment | setStyle(int styleRes) | threadHeader.setStyle(R.style.CustomThreadHeaderStyle) |
| Incoming bubble style (programmatic) | Activity/Fragment | setIncomingMessageBubbleStyle(int) | .setIncomingMessageBubbleStyle(R.style.CustomIncomingStyle) |
| Outgoing bubble style (programmatic) | Activity/Fragment | setOutgoingMessageBubbleStyle(int) | .setOutgoingMessageBubbleStyle(R.style.CustomOutgoingStyle) |
| Reply count background (programmatic) | Activity/Fragment | setReplyCountBackgroundColor(int) | .setReplyCountBackgroundColor(Color.parseColor("#FEEDE1")) |
| Reply count text color (programmatic) | Activity/Fragment | setReplyCountTextColor(int) | .setReplyCountTextColor(Color.parseColor("#F76808")) |
| Reply count text appearance (programmatic) | Activity/Fragment | setReplyCountTextAppearance(int) | .setReplyCountTextAppearance(R.style.CustomTextAppearance) |
| Internal adapter access | Activity/Fragment | getAdapter() | Advanced use only |
Accessibility
The component renders aRecyclerView containing the parent message bubble. The reply count text is readable by screen readers. Avatar images include content descriptions derived from the sender’s name.
For custom message templates provided via setTemplates or addTemplate, ensure you set android:contentDescription on visual-only elements so TalkBack can announce them. The default templates handle this automatically.
Reaction indicators and read receipts are visual-only by default. If screen reader descriptions are needed, provide them via custom templates with appropriate contentDescription attributes.