Skip to main content
CometChatMessageHeader is a header bar component that sits at the top of a chat screen, displaying the avatar, name, and status of the user or group in the conversation.

Where It Fits

CometChatMessageHeader sits at the top of a chat screen. Wire it alongside CometChatMessageList and CometChatMessageComposer to build a complete messaging layout.
activity_chat.xml

Quick Start

Add to your layout XML:
Set a User or Group on the component — this is required for it to display data:
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the UI Kit dependency added.

Actions and Events

Callback Methods

onBackPress

Fires when the user presses the back button in the header.

onError

Fires on internal errors (network failure, auth issue, SDK exception).

SDK Events (Real-Time, Automatic)

The component listens to these SDK events internally. No manual setup needed.

Functionality


Custom View Slots

Leading View

Replace the avatar / left section.

Subtitle View

Replace the subtitle text below the user’s or group’s name.

Trailing View

Replace the right section (action buttons).
Choosing between the trailing and auxiliary slots. These two slots have different semantics by design, in both Kotlin XML Views and Jetpack Compose. The auxiliary slot supplies custom content for the auxiliary section — the area that by default renders the voice/video call buttons — so providing it replaces those defaults, which is the intended way to take over that area entirely. The trailing slot is separate and has no default content, so it is purely additive. For extra header icons, use the trailing slot — the call buttons stay. Use the auxiliary slot when you deliberately want your own content in place of the call-button area.
  • Kotlin (XML Views): setTrailingView(...) (additive) vs setAuxiliaryViewListener(...) (replaces the auxiliary container, whose default child is CometChatCallButtons)
  • Jetpack Compose: trailingView = { ... } (additive) vs auxiliaryView = { ... } (renders instead of the default call-button area)

Item View

Replace the entire default header with a fully customized layout.

Style

Define a custom style in themes.xml:
themes.xml
See Component Styling for the full reference.

ViewModel

See ViewModel & Data for state observation and custom repositories.

Next Steps

Message List

Display messages in a conversation

Message Composer

Rich input for sending messages

Component Styling

Detailed styling reference

ViewModel & Data

Custom ViewModels and repositories