Skip to main content
Version: v4

Message Header

Overview

MessageHeader is a Component that showcases the User or Group details in the toolbar. Furthermore, it also presents a typing indicator and a back navigation button for ease of use.

Image

The MessageHeader is comprised of the following components:

ComponentsDescription
ListItem ComponentThis component’s view consists of avatar, status indicator , title, and subtitle. The fields are then mapped with the SDK’s user, group class.
Back ButtonBackButton 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.

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

Actions

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

The MessageHeader component does not have any exposed filters.

Events

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.

MessageHeaderStyle style = new MessageHeaderStyle();
style.setTypingIndicatorTextColor(Color.parseColor("#ff0000"));
messageHeader.setStyle(style);

The properties exposed by MessageHeaderStyle are as follows:

PropertyDescriptionCode
Border WidthUsed to set border.setBorderWidth(int)
Border ColorUsed to set border color.setBorderColor(@ColorInt int)
Corner RadiusUsed to set corner radius.setCornerRadius(float)
BackgroundUsed to set background colour.setBackground(@ColorInt int)
BackgroundUsed to set Drawable in background.setBackground(@Drawable )
BackIcon TintUsed to set back button icon tint.setBackIconTint(@ColorInt int)
TypingIndicator TextAppearanceUsed to set typing indicator textStyle.setTypingIndicatorTextAppearance(@StyleRes int)
TypingIndicator TextColorUsed to set typing indicator text color.setTypingIndicatorTextColor(@ColorInt int)
SubtitleText AppearanceUsed to set subtitle text style.setSubtitleTextAppearance(@StyleRes int)
SubtitleText ColorUsed to set subtitle text color.setSubtitleTextColor(@ColorInt int)
OnlineStatus ColorUsed 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.

AvatarStyle avatarStyle = new AvatarStyle();
avatarStyle.setBorderWidth(10);
avatarStyle.setBorderColor(Color.BLACK);
messageHeader.setAvatarStyle(avatarStyle);
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.

ListItemStyle listItemStyle = new ListItemStyle();
listItemStyle.setTitleColor(Color.BLACK);
messageHeader.setListItemStyle(listItemStyle);
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.

StatusIndicatorStyle statusIndicatorStyle = new StatusIndicatorStyle();
statusIndicatorStyle.setCornerRadius(3.5f);
statusIndicatorStyle.setBorderColor(Color.GREEN);
messageHeader.setStatusIndicatorStyle(statusIndicatorStyle);

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.

Image
CometChatMessageHeader header = findViewById(R.id.header);
header.setUser(user);
header.hideBackIcon(false);

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

PropertyDescriptionCode
User report Used to pass user object of which header specific details will be shown.setUser(user)
Group report Used to pass group object of which header specific details will be shown.setGroup(Group)
ProtectedGroupIconUsed to set custom protected group icon.setProtectedGroupIcon(@DrawableRes int)
PrivateGroupIconUsed to set custom private group icon.setPrivateGroupIcon(@DrawableRes int)
Hide BackIconUsed to toggle back button visibility.hideBackIcon(boolean)
Disable TypingUsed to enable /disable typing indicators.disableTyping(boolean)
Disable UsersPresenceUsed 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

Image

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.

custom_header_item.xml
<?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>
YourActivity.java
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);

SetSubtitleView

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

header.setSubtitleView()

Example

Image

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

<?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>
YourActivity.java
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;
}
});

SetBackIcon

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

header.setBackIcon(view);

Example

Image

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

<?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>
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);

SetMenu

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

 header.setMenu()

Example

Image

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

view_menu.xml
<?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>
    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;
}
});