CometChatTextFormatter
TheCometChatTextFormatter abstract class is the base for all formatters. Its constructor takes a char trackingCharacter that triggers the formatter when typed in the composer (e.g., @ for mentions, # for hashtags).
Key Override Methods
Pre-Send Hook
OverridehandlePreMessageSend(Context, BaseMessage) to modify a message before it’s sent. This is useful for attaching metadata, transforming text, or adding custom data to the message object.
Suggestion System
The formatter provides a built-in suggestion dropdown:Example: Custom Hashtag Formatter
- Kotlin
- Java
Registering Formatters
Register formatters on a component usingsetTextFormatters:
- Kotlin
- Java
Built-in Formatter: CometChatMentionsFormatter
The UI Kit includesCometChatMentionsFormatter as a built-in formatter that handles @mention detection, user suggestion lists, and spannable highlighting. It serves as a reference implementation for building custom formatters.
See the Mentions Formatter Guide for details.
Global Configuration via DataSource
Formatters can also be configured globally using theDataSource framework. Override getTextFormatters in a DataSourceDecorator to add formatters that apply across all components:
- Kotlin
- Java
Related
- DataSource & ChatConfigurator — Learn the full DataSource decorator framework.
- Mentions Formatter Guide — Built-in mentions formatter reference.
- Customization Overview — See all customization categories.