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

# Mentions Formatter

> Format @mentions in CometChat Android UI Kit messages with custom styles, mention suggestions, group member mentions, and tap handling.

<Accordion title="AI Integration Quick Reference">
  | Field          | Value                                                                                                          |
  | -------------- | -------------------------------------------------------------------------------------------------------------- |
  | Package        | `com.cometchat.chatuikit.shared.formatters`                                                                    |
  | Key class      | `CometChatMentionsFormatter` (extends `CometChatTextFormatter`)                                                |
  | Required setup | `CometChatUIKit.init()` then `CometChatUIKit.login("UID")`                                                     |
  | Purpose        | Format @mentions with styled tokens, suggestion list, and click handling for users and group members           |
  | Sample app     | [GitHub](https://github.com/cometchat/cometchat-uikit-android/tree/v5/sample-app-java)                         |
  | Related        | [ShortCut Formatter](/ui-kit/android/shortcut-formatter-guide) \| [All Guides](/ui-kit/android/guide-overview) |
</Accordion>

`CometChatMentionsFormatter` extends `CometChatTextFormatter` to format @mentions in text messages. It styles mention tokens, generates suggestion lists as users type, and handles click events on rendered mentions across the message composer, message bubbles, and conversations list.

| Capability              | Description                                                                   |
| ----------------------- | ----------------------------------------------------------------------------- |
| Mention formatting      | Auto-formats mention placeholders into styled spans                           |
| Custom styles           | Colors, fonts, and backgrounds per context (composer, bubbles, conversations) |
| User and group mentions | Works with both individual users and group members                            |
| Suggestion list         | Generates mention candidates from user input                                  |
| Click handling          | Listener interface for tap on rendered mentions                               |

***

## Usage

### 1. Create the formatter

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    val mentionFormatter = CometChatMentionsFormatter(context)
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context);
    ```
  </Tab>
</Tabs>

### 2. Add to a formatters list

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    val textFormatters: MutableList<CometChatTextFormatter> = ArrayList()
    textFormatters.add(mentionFormatter)
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    List<CometChatTextFormatter> textFormatters = new ArrayList<>();
    textFormatters.add(mentionFormatter);
    ```
  </Tab>
</Tabs>

### 3. Pass to a component

Use `setTextFormatters()` on [CometChatMessageComposer](/ui-kit/android/message-composer), [CometChatMessageList](/ui-kit/android/message-list), or [CometChatConversations](/ui-kit/android/conversations).

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    messageComposer.setTextFormatters(textFormatters)
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    messageComposer.setTextFormatters(textFormatters);
    ```
  </Tab>
</Tabs>

***

## Styling Mentions

### Mention Click Handling

Set a click listener for mentions in message bubbles:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/2JiXkJ8lq6PmPGlJ/images/6edf49c4-mentions_actions-cb71d40bd7f1fb80d33459157efdb658.png?fit=max&auto=format&n=2JiXkJ8lq6PmPGlJ&q=85&s=47e412c76aa88023e645327c7020cfa0" width="1280" height="800" data-path="images/6edf49c4-mentions_actions-cb71d40bd7f1fb80d33459157efdb658.png" />
</Frame>

<Tabs>
  <Tab title="Kotlin">
    ```kotlin lines theme={null}
    val mentionFormatter = CometChatMentionsFormatter(context)

    mentionFormatter.setOnMentionClick { context, user ->
        Toast.makeText(context, user.name, Toast.LENGTH_SHORT).show()
    }

    val textFormatters: MutableList<CometChatTextFormatter> = ArrayList()
    textFormatters.add(mentionFormatter)
    messageComposer.setTextFormatters(textFormatters)
    ```
  </Tab>

  <Tab title="Java">
    ```java lines theme={null}
    CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context);

    mentionFormatter.setOnMentionClick((context, user) -> {
        Toast.makeText(context, user.getName(), Toast.LENGTH_SHORT).show();
    });

    List<CometChatTextFormatter> textFormatters = new ArrayList<>();
    textFormatters.add(mentionFormatter);
    messageComposer.setTextFormatters(textFormatters);
    ```
  </Tab>
</Tabs>

### Composer Mention Style

Customize how mentions appear in the message composer input field:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/21UBnagXOw-XG0Sv/images/b2f00911-mentions_message_composer-b1d1dd7961bc3c2953e7439bb516200b.png?fit=max&auto=format&n=21UBnagXOw-XG0Sv&q=85&s=c886b57cd8be05c98b3bd434564b0fa4" width="1280" height="800" data-path="images/b2f00911-mentions_message_composer-b1d1dd7961bc3c2953e7439bb516200b.png" />
</Frame>

```xml themes.xml lines theme={null}
<style name="CustomMessageComposerMentionsStyle" parent="CometChatMessageComposerMentionsStyle">
    <item name="cometchatMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatMentionTextColor">#000000</item>
    <item name="cometchatMentionBackgroundColor">#000000</item>
    <item name="cometchatSelfMentionTextColor">#30A46C</item>
    <item name="cometchatSelfMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatSelfMentionBackgroundColor">#30A46C</item>
</style>
```

<Tabs>
  <Tab title="Kotlin">
    ```kotlin lines theme={null}
    val mentionFormatter = CometChatMentionsFormatter(context)
    mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomMessageComposerMentionsStyle)

    val textFormatters: MutableList<CometChatTextFormatter> = ArrayList()
    textFormatters.add(mentionFormatter)
    messageComposer.setTextFormatters(textFormatters)
    ```
  </Tab>

  <Tab title="Java">
    ```java lines theme={null}
    CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context);
    mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomMessageComposerMentionsStyle);

    List<CometChatTextFormatter> textFormatters = new ArrayList<>();
    textFormatters.add(mentionFormatter);
    messageComposer.setTextFormatters(textFormatters);
    ```
  </Tab>
</Tabs>

### Message Bubble Mention Style

Customize mentions in incoming and outgoing message bubbles:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/ugckbRl5Q-H7t8X2/images/e2732868-mentions_message_bubble-fccf9cbdd63a54c2f734803e4480418a.png?fit=max&auto=format&n=ugckbRl5Q-H7t8X2&q=85&s=b3ed052fde3bde70019367adac537f43" width="1280" height="800" data-path="images/e2732868-mentions_message_bubble-fccf9cbdd63a54c2f734803e4480418a.png" />
</Frame>

```xml themes.xml lines theme={null}
<style name="CustomIncomingMessageBubbleMentionStyle" parent="CometChatIncomingBubbleMentionsStyle">
    <item name="cometchatMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatMentionTextColor">#D6409F</item>
    <item name="cometchatMentionBackgroundColor">#D6409F</item>
    <item name="cometchatSelfMentionTextColor">#30A46C</item>
    <item name="cometchatSelfMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatSelfMentionBackgroundColor">#30A46C</item>
</style>

<style name="CustomOutgoingMessageBubbleMentionStyle" parent="CometChatOutgoingBubbleMentionsStyle">
    <item name="cometchatMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatMentionTextColor">#FFFFFF</item>
    <item name="cometchatMentionBackgroundColor">#F9F8FD</item>
    <item name="cometchatSelfMentionTextColor">#30A46C</item>
    <item name="cometchatSelfMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatSelfMentionBackgroundColor">#30A46C</item>
</style>
```

<Tabs>
  <Tab title="Kotlin">
    ```kotlin lines theme={null}
    val mentionFormatter = CometChatMentionsFormatter(context)
    mentionFormatter.setOutgoingBubbleMentionTextStyle(context, R.style.CustomOutgoingMessageBubbleMentionStyle)
    mentionFormatter.setIncomingBubbleMentionTextStyle(context, R.style.CustomIncomingMessageBubbleMentionStyle)

    val textFormatters: MutableList<CometChatTextFormatter> = ArrayList()
    textFormatters.add(mentionFormatter)
    messageList.setTextFormatters(textFormatters)
    ```
  </Tab>

  <Tab title="Java">
    ```java lines theme={null}
    CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context);
    mentionFormatter.setOutgoingBubbleMentionTextStyle(context, R.style.CustomOutgoingMessageBubbleMentionStyle);
    mentionFormatter.setIncomingBubbleMentionTextStyle(context, R.style.CustomIncomingMessageBubbleMentionStyle);

    List<CometChatTextFormatter> textFormatters = new ArrayList<>();
    textFormatters.add(mentionFormatter);
    messageList.setTextFormatters(textFormatters);
    ```
  </Tab>
</Tabs>

### Conversations Mention Style

Customize mentions in the conversations list last-message preview:

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-docs-rn-guide-message-privately/le8ibYc8lBJsShSE/images/55490fa9-mentions_conversations-1a7b847ad0af53848dc106216ac64e74.png?fit=max&auto=format&n=le8ibYc8lBJsShSE&q=85&s=60673bcb7af1e51ddf7a118ca123f387" width="1280" height="800" data-path="images/55490fa9-mentions_conversations-1a7b847ad0af53848dc106216ac64e74.png" />
</Frame>

```xml themes.xml lines theme={null}
<style name="CustomConversationsMentionsStyle" parent="CometChatConversationsMentionsStyle">
    <item name="cometchatMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatMentionTextColor">#D6409F</item>
    <item name="cometchatMentionBackgroundColor">#D6409F</item>
    <item name="cometchatSelfMentionTextColor">#30A46C</item>
    <item name="cometchatSelfMentionTextAppearance">?attr/cometchatTextAppearanceBodyRegular</item>
    <item name="cometchatSelfMentionBackgroundColor">#30A46C</item>
</style>
```

<Tabs>
  <Tab title="Kotlin">
    ```kotlin lines theme={null}
    val mentionFormatter = CometChatMentionsFormatter(context)
    mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomConversationsMentionsStyle)

    val textFormatters: MutableList<CometChatTextFormatter> = ArrayList()
    textFormatters.add(mentionFormatter)
    cometChatConversations.setTextFormatters(textFormatters)
    ```
  </Tab>

  <Tab title="Java">
    ```java lines theme={null}
    CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context);
    mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomConversationsMentionsStyle);

    List<CometChatTextFormatter> textFormatters = new ArrayList<>();
    textFormatters.add(mentionFormatter);
    cometChatConversations.setTextFormatters(textFormatters);
    ```
  </Tab>
</Tabs>

***

## Customization Matrix

| What you want to change                       | Where                        | Property/API                                            | Example                                                                                                         |
| --------------------------------------------- | ---------------------------- | ------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Maximum number of mentions allowed            | `CometChatMentionsFormatter` | `setMentionLimit(int limit)`                            | `mentionFormatter.setMentionLimit(5)`                                                                           |
| Group members fetched for mention suggestions | `CometChatMentionsFormatter` | `.setGroupMembersRequestBuilder(...)`                   | `.setGroupMembersRequestBuilder(group -> new GroupMembersRequest.GroupMembersRequestBuilder(group.getGuid()));` |
| Users fetched for mention suggestions         | `CometChatMentionsFormatter` | `.setUsersRequestBuilder(...)`                          | `.setUsersRequestBuilder(new UsersRequest.UsersRequestBuilder().friendsOnly(true));`                            |
| Who can be mentioned                          | `CometChatMentionsFormatter` | `.setMentionsType(...)`                                 | `.setMentionsType(UIKitConstants.MentionsType.USERS_AND_GROUP_MEMBERS)`                                         |
| Where mentions are visible                    | `CometChatMentionsFormatter` | `.setMentionsVisibility(...)`                           | `.setMentionsVisibility(UIKitConstants.MentionsVisibility.BOTH);`                                               |
| Click action on a mention                     | `CometChatMentionsFormatter` | `setOnMentionClick`                                     | `mentionFormatter.setOnMentionClick((context, user) -> { });`                                                   |
| Mention text style in composer                | `CometChatMentionsFormatter` | `setMessageComposerMentionTextStyle(context, styleRes)` | `mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomStyle)`                             |
| Mention text style in outgoing bubbles        | `CometChatMentionsFormatter` | `setOutgoingBubbleMentionTextStyle(context, styleRes)`  | `mentionFormatter.setOutgoingBubbleMentionTextStyle(context, R.style.CustomStyle)`                              |
| Mention text style in incoming bubbles        | `CometChatMentionsFormatter` | `setIncomingBubbleMentionTextStyle(context, styleRes)`  | `mentionFormatter.setIncomingBubbleMentionTextStyle(context, R.style.CustomStyle)`                              |
| Mention text style in conversations list      | `CometChatMentionsFormatter` | `setConversationsMentionTextStyle(context, styleRes)`   | `mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomStyle)`                               |

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Message Composer" icon="keyboard" href="/ui-kit/android/message-composer">
    Configure the composer where users type and send messages with mentions
  </Card>

  <Card title="Message List" icon="messages" href="/ui-kit/android/message-list">
    Configure the message list where mention-styled bubbles are displayed
  </Card>

  <Card title="Conversations" icon="comments" href="/ui-kit/android/conversations">
    Configure the conversations list where mention-styled previews appear
  </Card>

  <Card title="ShortCut Formatter" icon="bolt" href="/ui-kit/android/shortcut-formatter-guide">
    Add shortcut text expansion to the message composer
  </Card>
</CardGroup>
