> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Header

## Overview

`MessageHeader` is a [Component](/ui-kit/android/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-feature-react-native-sdk-quotedmessage-a/Lc9mXSk8oVxt1t7p/images/6fc1ac0d-message_header-3ef4b07948db07a2ec0b2aca8bcdc221.png?fit=max&auto=format&n=Lc9mXSk8oVxt1t7p&q=85&s=fe855f9bd51a1cbf26c99adea3ee142b" width="1280" height="240" data-path="images/6fc1ac0d-message_header-3ef4b07948db07a2ec0b2aca8bcdc221.png" />
</Frame>

***

## 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/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.

##### OnError

This action doesn't change the behavior of the component but rather listens for any errors that occur in the Users component.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setOnError(cometchatException -> {

        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setOnError {

        }
    ```
  </Tab>
</Tabs>

***

##### setOnBackPressListener

`OnBackPressListener` is triggered when you press the back button in the app bar. It has a predefined behavior; when clicked, it navigates to the previous activity. However, you can override this action using the following code snippet.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setOnBackPressListener(() -> {
                
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.onBackPressListener = OnBackPress {

        }
    ```
  </Tab>
</Tabs>

***

##### setNewChatButtonClick

`setOnNewChatButtonClick` is triggered when you press the new chat button in the app bar. It has a predefined behavior; when clicked, it navigates to the previous activity. However, you can override this action using the following code snippet.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setNewChatButtonClick(() -> {

        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setNewChatButtonClick {

        }
    ```
  </Tab>
</Tabs>

***

##### setChatHistoryButtonClick

`setChatHistoryButtonClick` is triggered when you press the chat history button in the app bar. It has a predefined behavior; when clicked, it navigates to the previous activity. However, you can override this action using the following code snippet.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setChatHistoryButtonClick(() -> {

        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setChatHistoryButtonClick {

        }
    ```
  </Tab>
</Tabs>

***

### 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/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.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/NYlKVet_SWy5r_yh/images/c761803d-message_header_styling-ae4670a5a130374818f37e2144246748.png?fit=max&auto=format&n=NYlKVet_SWy5r_yh&q=85&s=255958579d6a50edb204eebd37b59909" width="1280" height="240" data-path="images/c761803d-message_header_styling-ae4670a5a130374818f37e2144246748.png" />
</Frame>

```xml themes.xml theme={null}
    <style name="CustomCallButtonStyle" parent="CometChatCallButtonsStyle">
        <item name="cometchatCallButtonsVideoCallIconTint">#F76808</item>
        <item name="cometchatCallButtonsVoiceCallIconTint">#F76808</item>
    </style>

    <style name="CustomMessageHeaderStyle" parent="CometChatMessageHeaderStyle">
        <item name="cometchatMessageHeaderTitleTextColor">#F76808</item>
        <item name="cometchatMessageHeaderAvatarStyle">@style/CustomAvatarStyle</item>
        <item name="cometchatMessageHeaderCallButtonsStyle">@style/CustomCallButtonStyle</item>
    </style>
```

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    cometchatMessageHeader.setStyle(R.style.CustomMessageHeaderStyle);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    cometchatMessageHeader.setStyle(R.style.CustomMessageHeaderStyle)
    ```
  </Tab>
</Tabs>

***

To know more such attributes, visit the [attributes file](https://github.com/cometchat/cometchat-uikit-android/blob/v5/chatuikit/src/main/res/values/attr_cometchat_message_header.xml).

### 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.

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

| Property                           | Description                                                                                                                                              | Code                                          |
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| **User**                           | Used to pass user object of which header specific details will be shown. This is a one of the required property for the component to function properly.  | `.setUser(user)`                              |
| **Group**                          | Used to pass group object of which header specific details will be shown. This is a one of the required property for the component to function properly. | `.setGroup(Group)`                            |
| **setBackButtonVisibility**        | Used to toggle back button visibility                                                                                                                    | `.setBackButtonVisibility(View.GONE)`         |
| **setUserStatusVisibility**        | Used to toggle functionality to show user's presence                                                                                                     | `.setUserStatusVisibility(View.VISIBLE)`      |
| **setVideoCallButtonVisibility**   | Defines whether a user can initiate a video call                                                                                                         | `.setVideoCallButtonVisibility(View.VISIBLE)` |
| **setVoiceCallButtonVisibility**   | Defines whether a user can initiate a voice call                                                                                                         | `.setVoiceCallButtonVisibility(View.VISIBLE)` |
| **setNewChatButtonVisibility**     | Used to toggle the visibility of new chat button in case of chats with AI Assistants                                                                     | `.setNewChatButtonVisibility(View.GONE)`      |
| **setChatHistoryButtonVisibility** | Used to toggle the visibility of chat history button in case of chats with AI Assistants                                                                 | `.setChatHistoryButtonVisibility(View.GONE)`  |
| **setMenuIconVisibility**          | This method sets the visibility of the menu icon in the message header.                                                                                  | .setMenuIconVisibility(View\.VISIBLE);        |

### 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.

#### setDateTimeFormatter

By providing a custom implementation of the DateTimeFormatterCallback, you can configure how time and date values are displayed. This ensures consistent formatting for labels such as "Today", "Yesterday", "X minutes ago", and more.

Each method in the interface corresponds to a specific case:

`time(long timestamp)` → Custom full timestamp format

`today(long timestamp)` → Called when a message is from today

`yesterday(long timestamp)` → Called for yesterday’s messages

`lastWeek(long timestamp)` → Messages from the past week

`otherDays(long timestamp)` → Older messages

`minute(long timestamp)` / `hour(long timestamp)` → Exact time unit

`minutes(long diffInMinutesFromNow, long timestamp)` → e.g., "5 minutes ago"

`hours(long diffInHourFromNow, long timestamp)` → e.g., "2 hours ago"

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;


    cometchatMessageHeader.setDateTimeFormatter(new DateTimeFormatterCallback() {

            private final SimpleDateFormat fullTimeFormatter = new SimpleDateFormat("hh:mm a", Locale.getDefault());
            private final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd MMM yyyy", Locale.getDefault());

            @Override
            public String time(long timestamp) {
                return fullTimeFormatter.format(new Date(timestamp));
            }

            @Override
            public String today(long timestamp) {
                return "Today";
            }

            @Override
            public String yesterday(long timestamp) {
                return "Yesterday";
            }

            @Override
            public String lastWeek(long timestamp) {
                return "Last Week";
            }

            @Override
            public String otherDays(long timestamp) {
                return dateFormatter.format(new Date(timestamp));
            }

            @Override
            public String minutes(long diffInMinutesFromNow, long timestamp) {
                return diffInMinutesFromNow + " mins ago";
            }

            @Override
            public String hours(long diffInHourFromNow, long timestamp) {
                return diffInHourFromNow + " hrs ago";
            }
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    import java.text.SimpleDateFormat
    import java.util.*

    cometchatMessageHeader.setDateTimeFormatterCallback(object : DateTimeFormatterCallback {

            private val fullTimeFormatter = SimpleDateFormat("hh:mm a", Locale.getDefault())
            private val dateFormatter = SimpleDateFormat("dd MMM yyyy", Locale.getDefault())

            override fun time(timestamp: Long): String {
                return fullTimeFormatter.format(Date(timestamp))
            }

            override fun today(timestamp: Long): String {
                return "Today"
            }

            override fun yesterday(timestamp: Long): String {
                return "Yesterday"
            }

            override fun lastWeek(timestamp: Long): String {
                return "Last Week"
            }

            override fun otherDays(timestamp: Long): String {
                return dateFormatter.format(Date(timestamp))
            }

            override fun minutes(diffInMinutesFromNow: Long, timestamp: Long): String {
                return "$diffInMinutesFromNow mins ago"
            }

            override fun hours(diffInHourFromNow: Long, timestamp: Long): String {
                return "$diffInHourFromNow hrs ago"
            }
        });
    ```
  </Tab>
</Tabs>

***

#### setAuxiliaryButtonView

Allows adding a custom button or additional action next to the title or trailing section.

Use Cases:

* Add a Call button (📞) for quick voice/video calls.
* Include a Block/Report button for moderation.
* Implement a Pin Chat feature.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setAuxiliaryButtonView((context, user, group) -> {
                
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setAuxiliaryButtonView(object : Function3<Context?, User?, Group?, View?> {
                override fun apply(context: Context?, user: User?, group: Group?): View? {
                 
                }
            })
    ```
  </Tab>
</Tabs>

***

#### setOptions

Allows adding custom options menu which will show on header menu tap. The header menu will only be visible when options are set using this method.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
            List<CometChatPopupMenu.MenuItem> options = new ArrayList<>();

            options.add(new CometChatPopupMenu.MenuItem(
                    UIKitConstants.MessageHeaderMenuOptions.SEARCH,
                    getString(com.cometchat.chatuikit.R.string.cometchat_menu_search),
                    AppCompatResources.getDrawable(this, com.cometchat.chatuikit.R.drawable.cometchat_ic_search),
                    null,
                    this::navigateToSearchActivity
            ));

            options.add(new CometChatPopupMenu.MenuItem(
                    UIKitConstants.MessageHeaderMenuOptions.CONVERSATION_SUMMARY,
                    getString(com.cometchat.chatuikit.R.string.cometchat_menu_conversation_summary),
                    AppCompatResources.getDrawable(this, com.cometchat.chatuikit.R.drawable.cometchat_ic_menu_conversation_summary),
                    null,
                    this::generateConversationSummary
            ));

            binding.messageHeader.setOptions(options);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    val options = mutableListOf<CometChatPopupMenu.MenuItem>()
            options.add(
                CometChatPopupMenu.MenuItem(
                    UIKitConstants.MessageHeaderMenuOptions.SEARCH,
                    getString(com.cometchat.chatuikit.R.string.cometchat_menu_search),
                    AppCompatResources.getDrawable(this@MessagesActivity, com.cometchat.chatuikit.R.drawable.cometchat_ic_search),
                    null,
                ) { navigateToSearchActivity() }
            )
            options.add(
                CometChatPopupMenu.MenuItem(
                    UIKitConstants.MessageHeaderMenuOptions.CONVERSATION_SUMMARY,
                    getString(com.cometchat.chatuikit.R.string.cometchat_menu_conversation_summary),
                    AppCompatResources.getDrawable(this@MessagesActivity, com.cometchat.chatuikit.R.drawable.cometchat_ic_menu_conversation_summary),
                    null
                ) { generateConversationSummary() }
            )

    binding.messageHeader.options = options
    ```
  </Tab>
</Tabs>

***

#### setItemView

Enables replacing the entire default header with a fully customized ListItem layout.

Use Cases:

* Create a completely unique message header style.
* Include additional user details like bio, location, or last seen status.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setItemView((context, user, group) -> {
                
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setItemView(object : Function3<Context?, User?, Group?, View?> {
                override fun apply(context: Context?, user: User?, group: Group?): View? {
                 
                }
            })
    ```
  </Tab>
</Tabs>

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/Lc9mXSk8oVxt1t7p/images/6fc1ac0d-message_header-3ef4b07948db07a2ec0b2aca8bcdc221.png?fit=max&auto=format&n=Lc9mXSk8oVxt1t7p&q=85&s=fe855f9bd51a1cbf26c99adea3ee142b" width="1280" height="240" data-path="images/6fc1ac0d-message_header-3ef4b07948db07a2ec0b2aca8bcdc221.png" />
</Frame>

```xml custom_message_header.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:id="@+id/parent_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:padding="10dp">

    <ImageView
        android:id="@+id/iv_message_header_back"
        android:layout_width="@dimen/cometchat_24dp"
        android:layout_height="@dimen/cometchat_24dp"
        android:layout_gravity="center_vertical"
        android:src="@drawable/cometchat_ic_back"
        app:tint="@color/black"
        tools:ignore="ContentDescription" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/message_header_avatar_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/cometchat_margin_2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/message_header_back_icon_layout"
        app:layout_constraintTop_toTopOf="parent">

        <com.cometchat.chatuikit.shared.views.avatar.CometChatAvatar
            android:id="@+id/message_header_avatar_view"
            android:layout_width="@dimen/cometchat_40dp"
            android:layout_height="@dimen/cometchat_40dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <LinearLayout
        android:id="@+id/message_header_center_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/cometchat_margin_2"
        android:layout_marginEnd="@dimen/cometchat_padding_3"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent">

        <TextView
            android:id="@+id/tv_message_header_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:gravity="start"
            android:maxLines="1"
            android:text="hvfcghv"
            android:textAppearance="?attr/cometchatTextAppearanceHeading4Medium"
            android:textColor="?attr/cometchatTextColorPrimary" />


        <TextView
            android:id="@+id/tv_message_header_subtitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:gravity="center_vertical"
            android:marqueeRepeatLimit="1"
            android:minHeight="@dimen/cometchat_19dp"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:textAppearance="?attr/cometchatTextAppearanceCaption1Regular"
            android:textColor="?attr/cometchatTextColorSecondary" />


    </LinearLayout>

    <LinearLayout
        android:id="@+id/end_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.cometchat.chatuikit.calls.callbutton.CometChatCallButtons
            android:id="@+id/call_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/cometchat_margin_2" />
        
    </LinearLayout>


</LinearLayout>
```

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    cometchatMessageHeader.setItemView((context, user, group) -> {
                View view = LayoutInflater.from(context).inflate(R.layout.custom_message_header, null);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                                                                 LinearLayout.LayoutParams.WRAP_CONTENT);
                CometChatAvatar avatar = view.findViewById(R.id.message_header_avatar_view);
                TextView titleText = view.findViewById(R.id.tv_message_header_name);
                TextView subtitleText = view.findViewById(R.id.tv_message_header_subtitle);
                CometChatCallButtons cometChatCallButtons = view.findViewById(R.id.call_button);

                if (user != null) {
                    avatar.setAvatar(user.getName(), user.getAvatar());
                    titleText.setText(user.getName());
                    subtitleText.setText(user.getStatus());
                    cometChatCallButtons.setUser(user);
                } else {
                    avatar.setAvatar(group.getName(), group.getIcon());
                    titleText.setText(group.getName());
                    subtitleText.setText(group.getMembersCount() + " members");
                    cometChatCallButtons.setGroup(group);
                }
                view.setLayoutParams(params);
                return view;
            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    cometchatMessageHeader.setItemView { context, user, group ->
                val view: View = LayoutInflater.from(context).inflate(R.layout.custom_message_header, null)
                val params = LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT
                )
                val avatar = view.findViewById<CometChatAvatar>(R.id.message_header_avatar_view)
                val titleText = view.findViewById<TextView>(R.id.tv_message_header_name)
                val subtitleText = view.findViewById<TextView>(R.id.tv_message_header_subtitle)
                val cometChatCallButtons = view.findViewById<CometChatCallButtons>(R.id.call_button)

                if (user != null) {
                    avatar.setAvatar(user.name, user.avatar)
                    titleText.text = user.name
                    subtitleText.text = user.status
                    cometChatCallButtons.setUser(user)
                } else {
                    avatar.setAvatar(group.name, group.icon)
                    titleText.text = group.name
                    subtitleText.setText(group.membersCount + " members")
                    cometChatCallButtons.setGroup(group)
                }
                view.layoutParams = params
                view
            }
    ```
  </Tab>
</Tabs>

***

#### setSubtitleView

Allows customizing the subtitle view, usually used for status messages or additional details.

Use Cases:

* Show the user's last seen or online status.
* Display a custom typing indicator.
* Show a custom role or tagline ("Customer Support", "Verified Seller").

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setSubtitleView((context, user, group) -> {
                
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setSubtitleView(object : Function3<Context?, User?, Group?, View?> {
                override fun apply(context: Context?, user: User?, group: Group?): View? {
                 
                }
            })
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/kguwBmaySZvSdKIc/images/691ae5e8-message_header_subtitle_view-dc68ccaa0e5b42749247bd5e0b736f8f.png?fit=max&auto=format&n=kguwBmaySZvSdKIc&q=85&s=1ab08c6ef9a960e9e800fc4c77baa519" width="2560" height="480" data-path="images/691ae5e8-message_header_subtitle_view-dc68ccaa0e5b42749247bd5e0b736f8f.png" />
</Frame>

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

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometChatMessageHeader.setSubtitleView((context, user, group) -> {
                TextView textView = new TextView(context);
                if(user!=null) {
                    textView.setText(user.getStatus());
                }else if(group!=null) {
                    textView.setText(group.getMembersCount() > 1 ? group.getMembersCount() + " members" : group.getMembersCount() + " member" + " • " + group.getDescription());
                }
                return textView;
            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometChatMessageHeader.setSubtitleView(object : Function3<Context?, User?, Group?, View?> {
                override fun apply(context: Context?, user: User?, group: Group?): View? {
                    val textView = TextView(context)
                    if (user != null) {
                        textView.text = user.status
                    } else if (group != null) {
                        textView.text =
                            if (group.membersCount > 1) group.membersCount.toString() + " members" else group.membersCount.toString() + " member" + " • " + group.description
                    }
                    return textView
                }
            })
    ```
  </Tab>
</Tabs>

***

#### setLeadingView

Defines a custom leading view, typically used for the receiver's profile picture or avatar.

Use Cases:

* Display a circular profile picture with a status indicator.
* Add a custom badge for special roles (Admin, Verified ✅).

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setLeadingView((context, user, group) -> {
                
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setLeadingView(object : Function3<Context?, User?, Group?, View?> {
                override fun apply(context: Context?, user: User?, group: Group?): View? {
                 
                }
            })
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/bEkkKJAcvd9ivm_A/images/e09af665-message_header_leading_view-6d0be5fa6870e2bd8acf0af4b6393c93.png?fit=max&auto=format&n=bEkkKJAcvd9ivm_A&q=85&s=e43d7b2a2d21a16148179e18762f4f58" width="1280" height="240" data-path="images/e09af665-message_header_leading_view-6d0be5fa6870e2bd8acf0af4b6393c93.png" />
</Frame>

You need to create a `header_leading_view.xml` file, inflate it, and then pass it to the `.setLeadingView(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="@dimen/cometchat_45dp"
    android:layout_height="@dimen/cometchat_45dp"
    android:orientation="vertical">

    <com.cometchat.chatuikit.shared.views.avatar.CometChatAvatar
        android:id="@+id/avatar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <View
        android:id="@+id/batch_view"
        android:layout_width="match_parent"
        android:layout_height="@dimen/cometchat_12dp"
        android:layout_alignParentBottom="true"
        android:visibility="gone"
        android:background="@drawable/admin_batch" />

</RelativeLayout>
```

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    cometChatMessageHeader.setLeadingView(new Function3<Context, User, Group, View>() {
                @Override
                public View apply(Context context, User user, Group group) {
                    View view = LayoutInflater.from(context).inflate(R.layout.header_leading_view, null);
                    CometChatAvatar avatar = view.findViewById(R.id.avatar);
                    View view1 = view.findViewById(R.id.batch_view);
                    if (user != null) {
                        avatar.setAvatar(user.getName(), user.getAvatar());
                        if ("admin".equals(user.getRole())) {
                            view1.setVisibility(View.VISIBLE);
                        }
                    } else {
                        avatar.setAvatar(group.getName(), group.getIcon());
                        if (group.getOwner().equals(CometChatUIKit.getLoggedInUser().getUid())) {
                            view1.setVisibility(View.VISIBLE);
                        }
                    }

                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Utils.convertDpToPx(context, 45), Utils.convertDpToPx(context, 45));
                    view.setLayoutParams(params);
                    return view;
                }
            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    cometChatMessageHeader.leadingView = object : Function3<Context?, User?, Group?, View?> {
                override fun apply(t: Context?, k: User?, s: Group?): View? {
                    val view: View = LayoutInflater.from(context).inflate(R.layout.header_leading_view, null)
                    val avatar = view.findViewById<CometChatAvatar>(R.id.avatar)
                    val view1 = view.findViewById<View>(R.id.batch_view)
                    if (user != null) {
                        avatar.setAvatar(user.name, user.avatar)
                        if ("admin" == user.role) {
                            view1.visibility = View.VISIBLE
                        }
                    } else {
                        avatar.setAvatar(group.name, group.icon)
                        if (group.owner == CometChatUIKit.getLoggedInUser().uid) {
                            view1.visibility = View.VISIBLE
                        }
                    }

                    val params = LinearLayout.LayoutParams(Utils.convertDpToPx(context, 45), Utils.convertDpToPx(context, 45))
                    view.layoutParams = params
                    return view
                }
            }
    ```
  </Tab>
</Tabs>

***

#### setTrailingView

Enables customization of the trailing view, typically used for action buttons or indicators.

Use Cases:

* Add an options menu (⋮) for more actions.
* Display a mute/unmute toggle.
* Show a connection strength indicator for calls.

<Tabs>
  <Tab title="Java">
    ```java YourActivity.java theme={null}
    cometchatMessageHeader.setTrailingView((context, user, group) -> {
                
        });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin YourActivity.kt theme={null}
    cometchatMessageHeader.setTrailingView(object : Function3<Context?, User?, Group?, View?> {
                override fun apply(context: Context?, user: User?, group: Group?): View? {
                 
                }
        })
    ```
  </Tab>
</Tabs>

**Example**

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/-VkygUOl1ts-0wu1/images/b2a0551c-message_header_trailing_view-64dbdd471059cf2e92dc9646fb3e676b.png?fit=max&auto=format&n=-VkygUOl1ts-0wu1&q=85&s=e39e05028605ff577de10576e40f6fc3" width="2560" height="480" data-path="images/b2a0551c-message_header_trailing_view-64dbdd471059cf2e92dc9646fb3e676b.png" />
</Frame>

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    cometChatMessageHeader.setTrailingView((context, user, group) -> {
                ImageView imageView = new ImageView(context);
                imageView.setImageResource(R.drawable.save_icon);
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Utils.convertDpToPx(context, 24), Utils.convertDpToPx(context, 24));
                params.leftMargin = Utils.convertDpToPx(context, 16);
                imageView.setLayoutParams(params);
                return imageView;
            });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    cometChatMessageHeader.setTrailingView { context, user, group ->
                val imageView = ImageView(context)
                imageView.setImageResource(R.drawable.save_icon)
                val params = LinearLayout.LayoutParams(
                    Utils.convertDpToPx(context, 24),
                    Utils.convertDpToPx(context, 24)
                )
                params.leftMargin = Utils.convertDpToPx(context, 16)
                imageView.layoutParams = params
                imageView
            }
    ```
  </Tab>
</Tabs>
