> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-rn-guide-message-privately.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Header

> Message Header — CometChat documentation.

## Overview

`MessageHeader` is a [Component](/ui-kit/android/v4/components-overview#components) that showcases the [User](/sdk/android/users-overview) or [Group](/sdk/android/groups-overview) details in the toolbar. Furthermore, it also presents a typing indicator and a back navigation button for ease of use.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/Gp90C5sdVtuRR4t7/images/7fcb8466-message_header_overview_cometchat_screens-2b4b9bddcac8fca665a38e85b504c8a9.png?fit=max&auto=format&n=Gp90C5sdVtuRR4t7&q=85&s=56419b9dd7ec26c88fad4362bb11196a" width="4498" height="3120" data-path="images/7fcb8466-message_header_overview_cometchat_screens-2b4b9bddcac8fca665a38e85b504c8a9.png" />
</Frame>

The `MessageHeader` is comprised of the following components:

| Components                                         | Description                                                                                                                                    |
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| [ListItem Component](/ui-kit/android/v4/list-item) | This component’s view consists of avatar, status indicator , title, and subtitle. The fields are then mapped with the SDK’s user, group class. |
| Back Button                                        | BackButton that allows users to navigate back from the current activity or screen to the previous one                                          |

## Usage

### Integration

You can add `MessageHeader` component directly into the \`layout.xml\`\` file.

```xml your_layout.xml theme={null}
<com.cometchat.chatuikit.messageheader.CometChatMessageHeader
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="56dp" />
```

### Actions

[Actions](/ui-kit/android/v4/components-overview#actions) dictate how a component functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.

The `MessageHeader` component does not have any exposed actions.

### Filters

**Filters** allow you to customize the data displayed in a list within a `Component`. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using `RequestBuilders` of Chat SDK.

The `MessageHeader` component does not have any exposed filters.

### Events

[Events](/ui-kit/android/v4/components-overview#events) are emitted by a `Component`. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.

The `MessageHeader` component does not produce any events.

## Customization

To fit your app's design requirements, you can customize the appearance of the conversation component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

### Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

##### 1. MessageHeader Style

To customize the appearance, you can assign a `MessageHeaderStyle` object to the `MessageHeader` component.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    MessageHeaderStyle style = new MessageHeaderStyle();
    style.setTypingIndicatorTextColor(Color.parseColor("#ff0000"));
    messageHeader.setStyle(style);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val style = MessageHeaderStyle()
    style.typingIndicatorTextColor = Color.parseColor("#ff0000")
    messageHeader.setStyle(style)
    ```
  </Tab>
</Tabs>

The properties exposed by `MessageHeaderStyle` are as follows:

| Property                           | Description                             | Code                                               |
| ---------------------------------- | --------------------------------------- | -------------------------------------------------- |
| **Border Width**                   | Used to set border                      | `.setBorderWidth(int)`                             |
| **Border Color**                   | Used to set border color                | `.setBorderColor(@ColorInt int)`                   |
| **Corner Radius**                  | Used to set corner radius               | `.setCornerRadius(float)`                          |
| **Background**                     | Used to set background colour           | `.setBackground(@ColorInt int)`                    |
| **Background**                     | Used to set Drawable in background      | `.setBackground(@Drawable )`                       |
| **BackIcon Tint**                  | Used to set back button icon tint       | `.setBackIconTint(@ColorInt int)`                  |
| **TypingIndicator TextAppearance** | Used to set typing indicator textStyle  | `.setTypingIndicatorTextAppearance(@StyleRes int)` |
| **TypingIndicator TextColor**      | Used to set typing indicator text color | `.setTypingIndicatorTextColor(@ColorInt int)`      |
| **SubtitleText Appearance**        | Used to set subtitle text style         | `.setSubtitleTextAppearance(@StyleRes int)`        |
| **SubtitleText Color**             | Used to set subtitle text color         | `.setSubtitleTextColor(@ColorInt int)`             |
| **OnlineStatus Color**             | Used to set online status colour        | `.setOnlineStatusColor(@ColorInt int)`             |

##### 2. Avatar Style

If you want to apply customized styles to the `Avatar` component within the `MessageHeader` Component, you can use the following code snippet. For more information you can refer [Avatar Styles](/ui-kit/android/v4/avatar#avatarstyle).

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    AvatarStyle avatarStyle = new AvatarStyle();
    avatarStyle.setBorderWidth(10);
    avatarStyle.setBorderColor(Color.BLACK);
    messageHeader.setAvatarStyle(avatarStyle);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val avatarStyle = AvatarStyle()
    avatarStyle.borderWidth = 10
    avatarStyle.borderColor = Color.BLACK
    messageHeader.setAvatarStyle(avatarStyle)
    ```
  </Tab>
</Tabs>

##### 3. ListItem Style

If you want to apply customized styles to the `ListItemStyle` component within the `MessageHeader` Component, you can use the following code snippet. For more information, you can refer [ListItem Styles](/ui-kit/android/v4/list-item#listitemstyle).

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    ListItemStyle listItemStyle = new ListItemStyle();
    listItemStyle.setTitleColor(Color.BLACK);
    messageHeader.setListItemStyle(listItemStyle);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val listItemStyle = ListItemStyle()
    listItemStyle.setTitleColor(Color.BLACK)
    messageHeader.setListItemStyle(listItemStyle)
    ```
  </Tab>
</Tabs>

##### 4. StatusIndicator Style

If you want to apply customized styles to the `Status Indicator` component within the `MessageHeader` Component, you can use the following code snippet. For more information you can refer [StatusIndicator Styles](/ui-kit/android/v4/status-indicator#methods).

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    StatusIndicatorStyle statusIndicatorStyle = new StatusIndicatorStyle();
            statusIndicatorStyle.setCornerRadius(3.5f);
            statusIndicatorStyle.setBorderColor(Color.GREEN);
            messageHeader.setStatusIndicatorStyle(statusIndicatorStyle);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val statusIndicatorStyle = StatusIndicatorStyle()
    statusIndicatorStyle.cornerRadius = 3.5f
    statusIndicatorStyle.borderColor = Color.GREEN
    messageHeader.setStatusIndicatorStyle(statusIndicatorStyle)
    ```
  </Tab>
</Tabs>

### Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

Here is a code snippet demonstrating how you can customize the functionality of the Message Header component.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/G6Puyz_3Zlaowa9R/images/c95344bc-message_header_functionality_cometchat_screens-e6d9c94cb2c2337827faab408945c550.png?fit=max&auto=format&n=G6Puyz_3Zlaowa9R&q=85&s=a87fe0388714c476016eafe821c980ed" width="4498" height="3120" data-path="images/c95344bc-message_header_functionality_cometchat_screens-e6d9c94cb2c2337827faab408945c550.png" />
</Frame>

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChatMessageHeader header = findViewById(R.id.header);
    header.setUser(user);
    header.hideBackIcon(false);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val header = findViewById<CometChatMessageHeader>(R.id.header)
    header.setUser(user)
    header.hideBackIcon(false)
    ```
  </Tab>
</Tabs>

Following is a list of customizations along with their corresponding code snippets:

| Property                                            | Description                                                              | Code                                       |
| --------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------ |
| **User** <Tooltip tip="Not available">🛑</Tooltip>  | Used to pass user object of which header specific details will be shown  | `.setUser(user)`                           |
| **Group** <Tooltip tip="Not available">🛑</Tooltip> | Used to pass group object of which header specific details will be shown | `.setGroup(Group)`                         |
| **ProtectedGroupIcon**                              | Used to set custom protected group icon                                  | `.setProtectedGroupIcon(@DrawableRes int)` |
| **PrivateGroupIcon**                                | Used to set custom private group icon                                    | `.setPrivateGroupIcon(@DrawableRes int)`   |
| **Hide BackIcon**                                   | Used to toggle back button visibility                                    | `.hideBackIcon(boolean)`                   |
| **Disable Typing**                                  | Used to enable /disable typing indicators                                | `.disableTyping(boolean)`                  |
| **Disable UsersPresence**                           | Used to toggle functionality to show user's presence                     | `.disableUsersPresence(boolean)`           |

### Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.

#### SetListItemView

The `MessageHeader` component consists of a `ListItemView`. You can customize the ListItem according to your requirements by using the `.setListItemView` method.

```
header.setListItemView(View);
```

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/NN4EdpOU3viwWMb_/images/0a6a9f0c-message_header_set_list_item_cometchat_screens-d68d251143251bc8ada637324a7dd656.png?fit=max&auto=format&n=NN4EdpOU3viwWMb_&q=85&s=6d1915cd841b09a64eb8da49f7de55ee" width="4498" height="3120" data-path="images/0a6a9f0c-message_header_set_list_item_cometchat_screens-d68d251143251bc8ada637324a7dd656.png" />
</Frame>

You have to create a `custom_header_item.xml` as a custom layout file. This file can then be inflated and passed to `setListItemView()` method.

```xml custom_header_item.xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="54dp"
        app:cardBackgroundColor="@color/white"
        app:cardCornerRadius="10dp"
        android:layout_margin="5dp"
        android:elevation="20dp"
        >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <com.cometchat.chatuikit.shared.views.CometChatAvatar.CometChatAvatar
                android:id="@+id/avatar_view"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_centerVertical="true"
                app:cardCornerRadius="10dp"
                />
            <TextView
                android:id="@+id/txt_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Name"
                android:layout_toRightOf="@+id/avatar_view"
                android:textSize="30sp"
                android:layout_centerVertical="true"
                />
        </RelativeLayout>
    </androidx.cardview.widget.CardView>
</RelativeLayout>
```

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    View view = getLayoutInflater().inflate(R.layout.custom_header_item, null);
    CometChatAvatar avatar = view.findViewById(R.id.avatar_view);
    TextView name = view.findViewById(R.id.txt_name);
    avatar.setImage(user.getAvatar());
    name.setText(user.getName());
    header.setListItemView(view);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    val view = layoutInflater.inflate(R.layout.custom_header_item, null)
    val avatar = view.findViewById<CometChatAvatar>(R.id.avatar_view)
    val name = view.findViewById<TextView>(R.id.txt_name)
    avatar.setImage(user.avatar)
    name.text = user.name
    header.setListItemView(view)
    ```
  </Tab>
</Tabs>

***

#### SetSubtitleView

By using the `.setSubtitleView` method, you can modify the SubtitleView to meet your specific needs.

```
header.setSubtitleView()
```

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/mq8rEbFfi0JjKmkM/images/65d84fb4-message_header_set_subtitle_view_cometchat_screens-5659ffcefe0d5f13bf2e89cbe7c4a666.png?fit=max&auto=format&n=mq8rEbFfi0JjKmkM&q=85&s=6b8e6e15d8f820e1c6bf683a13101d8d" width="4498" height="3120" data-path="images/65d84fb4-message_header_set_subtitle_view_cometchat_screens-5659ffcefe0d5f13bf2e89cbe7c4a666.png" />
</Frame>

You should create a `subtitle_layout.xml` file and inflate it inside `apply` function.

```html theme={null}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/img_conversation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_message_grey"
        android:layout_margin="2dp"
        />
    <ImageView
        android:id="@+id/img_audio_call"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_call"
        android:layout_margin="2dp"
        android:layout_toRightOf="@+id/img_conversation"
        />
    <ImageView
        android:id="@+id/img_video_call"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_video"
        android:layout_margin="2dp"
        android:layout_toRightOf="@+id/img_audio_call"
        />
</RelativeLayout>
```

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    header.setSubtitleView(new Function3<Context, User, Group, View>() {
        @Override
        public View apply(Context context, User user, Group group) {
            View view = getLayoutInflater().inflate(R.layout.subtitle_layout, null);
            ImageView imgConversation = view.findViewById(R.id.img_conversation);
            ImageView imgAudioCall = view.findViewById(R.id.img_audio_call);;
            ImageView imgVideCall = view.findViewById(R.id.img_video_call);
            imgConversation.setOnClickListener(v -> {
                Toast.makeText(context, "Conversation Clicked", Toast.LENGTH_SHORT).show();
            })
            imgAudioCall.setOnClickListener(v -> {
                Toast.makeText(context, "Audio Call Clicked", Toast.LENGTH_SHORT).show();
            })
            imgVideCall.setOnClickListener(v -> {
                Toast.makeText(context, "Video Call Clicked", Toast.LENGTH_SHORT).show();
            });
            return view;
        }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    header.setSubtitleView { context, user, group ->
        val view = layoutInflater.inflate(R.layout.subtitle_layout, null)
        val imgConversation = view.findViewById<ImageView>(R.id.img_conversation)
        val imgAudioCall = view.findViewById<ImageView>(R.id.img_audio_call)
        val imgVideoCall = view.findViewById<ImageView>(R.id.img_video_call)

        imgConversation.setOnClickListener {
            Toast.makeText(context, "Conversation Clicked", Toast.LENGTH_SHORT).show()
        }
        imgAudioCall.setOnClickListener {
            Toast.makeText(context, "Audio Call Clicked", Toast.LENGTH_SHORT).show()
        }
        imgVideoCall.setOnClickListener {
            Toast.makeText(context, "Video Call Clicked", Toast.LENGTH_SHORT).show()
        }
        view
    }
    ```
  </Tab>
</Tabs>

***

#### SetBackIcon

You can customize the Back Icon according to your specific requirements by using the `.setBackIcon()` method.

```
header.setBackIcon(view);
```

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/PrOf0fpV33FkfOMB/images/1640855a-message_header_set_back_button_cometchat_screens-896113ef95649e7647b70bf38243d7f0.png?fit=max&auto=format&n=PrOf0fpV33FkfOMB&q=85&s=1ca4e4d925d9bf5c4dbce96f5d490a42" width="4498" height="3120" data-path="images/1640855a-message_header_set_back_button_cometchat_screens-896113ef95649e7647b70bf38243d7f0.png" />
</Frame>

You need to create a `custom_header_back_icon.xml` file, inflate it, and then pass it to the `.setBackIcon(view)` method.

```html theme={null}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:elevation="20dp"
        android:backgroundTint="#6851D6"
        app:cardCornerRadius="20dp"
        >
        <ImageView
            android:id="@+id/img_back"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_back_ios"
            android:padding="5dp"
            />
    </androidx.cardview.widget.CardView>
</RelativeLayout>
```

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    View view = getLayoutInflater().inflate(R.layout.custom_header_back_icon, null);
    ImageView imgBack = view.findViewById(R.id.img_back);
    imgBack.setOnClickListener(v -> {
        Toast.makeText(this, "BackIcon Clicked !!", Toast.LENGTH_SHORT).show();
    });
    header.setBackIcon(view);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val view = layoutInflater.inflate(R.layout.custom_header_back_icon, null)
    val imgBack = view.findViewById<ImageView>(R.id.img_back)
    imgBack.setOnClickListener {
        Toast.makeText(this, "BackIcon Clicked !!", Toast.LENGTH_SHORT).show()
    }
    header.setBackIcon(view)
    ```
  </Tab>
</Tabs>

***

#### SetMenu

You can customize the Menu options to meet your specific needs by using the `.setMenu()` method.

```
 header.setMenu()
```

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/21UBnagXOw-XG0Sv/images/af4064de-message_header_set_menu_cometchat_screens-f6fcd0fe311f271a5dc9651ba2b31505.png?fit=max&auto=format&n=21UBnagXOw-XG0Sv&q=85&s=2f74653462b8af71d76c1008f26f99ba" width="4498" height="3120" data-path="images/af4064de-message_header_set_menu_cometchat_screens-f6fcd0fe311f271a5dc9651ba2b31505.png" />
</Frame>

You need to create a `view_menu.xml` file, inflate it, and then return it from `.setBackIcon(view)` method.

```xml view_menu.xml theme={null}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/img_refresh"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@drawable/ic_refresh_black"
        />
</LinearLayout>
```

<Tabs>
  <Tab title="Java">
    ```java theme={null}
        header.setMenu(new Function3<Context, User, Group, View>() {
                @Override
                public View apply(Context context, User user, Group group) {
                    View view = getLayoutInflater().inflate(R.layout.view_menu, null);
                    ImageView imgRefresh = view.findViewById(R.id.img_refresh);
                    imgRefresh.setOnClickListener(v -> {
                        //Your Action
                    });
                    return view;
                }
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    header.setMenu { context, user, group ->
        val view = layoutInflater.inflate(R.layout.view_menu, null)
        val imgRefresh = view.findViewById<ImageView>(R.id.img_refresh)
        imgRefresh.setOnClickListener {
            // Your Action
        }
        view
    }
    ```
  </Tab>
</Tabs>
