Documentation Index Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
AI Integration Quick Reference
Field Value Packages com.cometchat:chatuikit-kotlin · com.cometchat:chatuikit-jetpackKey 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 Related ShortCut Formatter | All Guides
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
Kotlin (XML Views)
Jetpack Compose
val mentionFormatter = CometChatMentionsFormatter (context)
val mentionFormatter = CometChatMentionsFormatter (context)
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
3. Pass to a component
Use setTextFormatters() on CometChatMessageComposer , CometChatMessageList , or CometChatConversations .
Kotlin (XML Views)
Jetpack Compose
messageComposer. setTextFormatters (textFormatters)
CometChatMessageComposer (
user = user,
textFormatters = textFormatters
)
Styling Mentions
Mention Click Handling
Set a click listener for mentions in message bubbles:
Kotlin (XML Views)
Jetpack Compose
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)
val mentionFormatter = CometChatMentionsFormatter (context)
mentionFormatter. setOnMentionClick { ctx, user ->
Toast. makeText (ctx, user.name, Toast.LENGTH_SHORT). show ()
}
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
CometChatMessageComposer (
user = chatUser,
textFormatters = textFormatters
)
Composer Mention Style
Customize how mentions appear in the message composer input field:
< 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 >
Kotlin (XML Views)
Jetpack Compose
val mentionFormatter = CometChatMentionsFormatter (context)
mentionFormatter. setMessageComposerMentionTextStyle (context, R.style.CustomMessageComposerMentionsStyle)
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
messageComposer. setTextFormatters (textFormatters)
val mentionFormatter = CometChatMentionsFormatter (context)
mentionFormatter. setMessageComposerMentionTextStyle (context, R.style.CustomMessageComposerMentionsStyle)
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
CometChatMessageComposer (
user = chatUser,
textFormatters = textFormatters
)
Message Bubble Mention Style
Customize mentions in incoming and outgoing message bubbles:
< 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 >
Kotlin (XML Views)
Jetpack Compose
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)
val mentionFormatter = CometChatMentionsFormatter (context)
mentionFormatter. setOutgoingBubbleMentionTextStyle (context, R.style.CustomOutgoingMessageBubbleMentionStyle)
mentionFormatter. setIncomingBubbleMentionTextStyle (context, R.style.CustomIncomingMessageBubbleMentionStyle)
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
CometChatMessageList (
user = chatUser,
textFormatters = textFormatters,
modifier = Modifier. weight ( 1f )
)
Conversations Mention Style
Customize mentions in the conversations list last-message preview:
< 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 >
Kotlin (XML Views)
Jetpack Compose
val mentionFormatter = CometChatMentionsFormatter (context)
mentionFormatter. setConversationsMentionTextStyle (context, R.style.CustomConversationsMentionsStyle)
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
cometChatConversations. setTextFormatters (textFormatters)
val mentionFormatter = CometChatMentionsFormatter (context)
mentionFormatter. setConversationsMentionTextStyle (context, R.style.CustomConversationsMentionsStyle)
val textFormatters: MutableList < CometChatTextFormatter > = ArrayList ()
textFormatters. add (mentionFormatter)
CometChatConversations (
textFormatters = textFormatters,
onItemClick = { conversation -> /* navigate */ }
)
Customization Matrix
What you want to change Where Property/API Example Maximum number of mentions allowed CometChatMentionsFormattersetMentionLimit(int limit)mentionFormatter.setMentionLimit(5)Group members fetched for mention suggestions CometChatMentionsFormatter.setGroupMembersRequestBuilder(...).setGroupMembersRequestBuilder(group -> GroupMembersRequest.GroupMembersRequestBuilder(group.guid))Users fetched for mention suggestions CometChatMentionsFormatter.setUsersRequestBuilder(...).setUsersRequestBuilder(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 CometChatMentionsFormattersetOnMentionClickmentionFormatter.setOnMentionClick { context, user -> }Mention text style in composer CometChatMentionsFormattersetMessageComposerMentionTextStyle(context, styleRes)mentionFormatter.setMessageComposerMentionTextStyle(context, R.style.CustomStyle)Mention text style in outgoing bubbles CometChatMentionsFormattersetOutgoingBubbleMentionTextStyle(context, styleRes)mentionFormatter.setOutgoingBubbleMentionTextStyle(context, R.style.CustomStyle)Mention text style in incoming bubbles CometChatMentionsFormattersetIncomingBubbleMentionTextStyle(context, styleRes)mentionFormatter.setIncomingBubbleMentionTextStyle(context, R.style.CustomStyle)Mention text style in conversations list CometChatMentionsFormattersetConversationsMentionTextStyle(context, styleRes)mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomStyle)
Next Steps
Message Composer Configure the composer where users type and send messages with mentions
Message List Configure the message list where mention-styled bubbles are displayed
Conversations Configure the conversations list where mention-styled previews appear
ShortCut Formatter Add shortcut text expansion to the message composer