Skip to main content

Where It Fits

CometChatMessageComposer is an input component. It renders the message input area and sends messages to the active conversation. Wire it with CometChatMessageHeader and CometChatMessageList to build a complete messaging layout.
ChatActivity.kt

Quick Start

Add the component to your layout XML:
layout_activity.xml
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.
The MessageComposer is responsible for managing runtime permissions. To ensure the ActivityResultLauncher is properly initialized, its object should be created in the onCreate state of an activity. To ensure that the composer is loaded within the fragment, it is important to make sure that the fragment is loaded in the onCreate state of the activity.
To add programmatically in an Activity:
YourActivity.kt
Or in a Fragment:
YourFragment.kt

Actions and Events

Callback Methods

setOnSendButtonClick

Fires when the send button is tapped. Primary hook — override to intercept or replace the default message-sending logic.
YourActivity.kt
What this does: Replaces the default send-button behavior. When a user taps the send button, your custom lambda executes instead of the built-in message sending logic.

setOnError

Fires on internal errors (network failure, auth issue, SDK exception).
YourActivity.kt
What this does: Registers an error listener. If the component encounters an error, your callback receives the CometChatException.

setOnTextChangedListener

Fires whenever the message input’s text value changes, enabling dynamic text handling.
YourActivity.kt
What this does: Registers a CometChatTextWatcher that fires callbacks when the text in the composer input field changes. Use onTextChanged for real-time character tracking, beforeTextChanged for pre-change state, and afterTextChanged for post-change processing.
  • Verify: After setting an action callback, trigger the corresponding user interaction (tap send, type text) and confirm your custom logic executes instead of the default behavior.

Global UI Events (CometChatMessageEvents)

The MessageComposer component does not emit any events of its own. However, message-related events can be observed via CometChatMessageEvents from other components in the messaging flow.

SDK Events

The MessageComposer component does not attach SDK listeners directly. Typing indicators are managed internally when disableTypingEvents is false (default).

Functionality

Small functional customizations such as toggling visibility of UI elements and configuring composer behavior.
  • Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden.

Custom View Slots

Each slot replaces a section of the default composer UI.

setHeaderView

Sets a custom view above the text input area.
What this does: Sets a custom View as the header of the composer. The header view renders above the text input area.
Example with a “Notes” card header:
Create a custom_header_layout.xml layout:
custom_header_layout.xml

setFooterView

Sets a custom view below the text input area.
What this does: Sets a custom View as the footer of the composer. The footer view renders below the text input area.

setSendButtonView

Replaces the default send button with a custom view.
What this does: Replaces the default send button with your custom View. The custom view takes over the send button position in the composer.
Custom send button example:
First, create a custom send button drawable:
drawable/custom_send_button.xml

setAuxiliaryButtonView

Replaces the auxiliary button area. The default auxiliary area provides sticker and AI functionality.
The MessageComposer uses the AuxiliaryButton for sticker functionality. If you override it with setAuxiliaryButtonView(), retrieve the default auxiliary buttons via CometChatUIKit.getDataSource().getAuxiliaryOption() and include them in your custom layout to preserve sticker/AI buttons.
Custom SOS button example:
What this does: Creates a horizontal LinearLayout containing the default auxiliary buttons (retrieved via CometChatUIKit.getDataSource().getAuxiliaryOption()) and a custom ImageView. The combined layout replaces the default auxiliary button area, preserving the existing sticker/AI buttons while adding a custom button.

setAttachmentOptions

Replaces the default attachment options with a custom list of CometChatMessageComposerAction objects.
Custom attachment options example:
What this does: Creates four custom CometChatMessageComposerAction objects, each with a title, icon, and click handler. The list replaces the default attachment options (camera, image, video, audio, file, poll, etc.) with these four custom actions.

setAIOptions

Replaces the default AI options with a custom provider function.
What this does: Registers a function that returns a list of CometChatMessageComposerAction objects for the AI options sheet. The function receives the current context, user, group, and ID map.

setTextFormatters

Assigns a list of text formatters. If the provided list is not null, it sets the list. Otherwise, it assigns the default text formatters. To configure the existing Mentions look and feel check out CometChatMentionsFormatter.
themes.xml
What this does: Creates a CometChatMentionsFormatter, applies the custom mentions style to it, adds it to a list of text formatters, and sets that list on the CometChatMessageComposer. Mentions in the composer input will render with the custom colors and text appearance.

setSuggestionListItemView

Replaces the default suggestion list item view with a custom view holder listener.
What this does: Registers a SuggestionListViewHolderListener that provides a custom view for each item in the suggestion list (e.g., mentions dropdown).
  • Verify: After setting any custom view slot, confirm the custom view renders in the correct position within the composer, and the data binding populates correctly.

Common Patterns

Text-only composer

Custom attachment options only

Disable voice recording

Prefilled composer with disabled typing events

Advanced Methods

setUser / setGroup

Associates the composer with a specific conversation. Use setUser for one-on-one and setGroup for group conversations.

setParentMessageId

Sets the parent message ID for threaded replies. When set, messages sent from the composer are sent as replies to the specified parent message.

setInitialComposerText

Sets predefined text in the composer input field.

getText / getProcessedText

Returns the current text from the composer. getText returns the raw text, while getProcessedText returns text with formatting (mentions, etc.) applied.

Internal Access

These methods provide direct access to internal components for advanced use cases.
Use these only when the standard API is insufficient. Directly manipulating the ViewModel or internal views may conflict with the component’s internal state management.

Style

The component uses XML theme styles. Define a custom style with parent CometChatMessageComposerStyle in themes.xml, then apply with setStyle().
First, create a custom send button drawable:
Then define the custom style in themes.xml:
themes.xml
To know more such attributes, visit the attributes file.

Programmatic Style Properties

In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:

Edit Preview Style Properties

When editing a message, a preview appears above the input. These properties control its appearance:

Customization Matrix

Next Steps

Message Header

Display user/group info in the toolbar

Message List

Display messages in a conversation

Conversations

Browse recent conversations

Theming

Customize colors, fonts, and styles