Guide Overview
Language/Framework: Java/Kotlin
UI Kit Version:
implementation 'com.cometchat:chat-uikit-android:4.3.13'
This guide can be used to customize the style of DateSeperator in the message list.
Define an custom DateStyle.
Java
DateStyle dateStyle = new DateStyle();
dateStyle.setBackgroundColor(ContextCompat.getColor(requireContext(),R.color.red));
dateStyle.setTextColor(ContextCompat.getColor(requireContext(),R.color.yellow));
Kotlin
val dateStyle = DateStyle()
dateStyle.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.red))
dateStyle.setTextColor(ContextCompat.getColor(requireContext(), R.color.yellow))
Create a MessageListConfiguration.
Java
MessageListConfiguration messageListConfiguration = new MessageListConfiguration();
messageListConfiguration.setDateSeparatorStyle(dateStyle);
Kotlin
val messageListConfiguration = MessageListConfiguration()
messageListConfiguration.setDateSeparatorStyle(dateStyle)
Pass the messageListConfiguration to the MessageConfiguration.
Java
MessagesConfiguration messagesConfiguration = new MessagesConfiguration();
messagesConfiguration.setMessageListConfiguration(messageListConfiguration);
Kotlin
val messagesConfiguration = MessagesConfiguration()
messagesConfiguration.setMessageListConfiguration(messageListConfiguration)
Modify the CometChat Component
Use the ConversationsWithMessages component to view the updated dateSeperator.
Java
CometChatConversationsWithMessages cometChatConversationsWithMessages = view.findViewById(R.id.conversationWithMessages);
cometChatConversationsWithMessages.setMessagesConfiguration(messagesConfiguration);
Kotlin
val cometChatConversationsWithMessages: CometChatConversationsWithMessages =
view.findViewById(R.id.conversationWithMessages)
cometChatConversationsWithMessages.messagesConfiguration = messagesConfiguration
Full Code
Java
DateStyle dateStyle = new DateStyle();
dateStyle.setBackgroundColor(ContextCompat.getColor(requireContext(),R.color.red));
dateStyle.setTextColor(ContextCompat.getColor(requireContext(),R.color.yellow));
MessageListConfiguration messageListConfiguration = new MessageListConfiguration();
messageListConfiguration.setDateSeparatorStyle(dateStyle);
MessagesConfiguration messagesConfiguration = new MessagesConfiguration();
messagesConfiguration.setMessageListConfiguration(messageListConfiguration);
CometChatConversationsWithMessages cometChatConversationsWithMessages = view.findViewById(R.id.conversationWithMessages);
cometChatConversationsWithMessages.setMessagesConfiguration(messagesConfiguration);
Kotlin
val dateStyle = DateStyle()
dateStyle.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.red))
dateStyle.setTextColor(ContextCompat.getColor(requireContext(), R.color.yellow))
val messageListConfiguration = MessageListConfiguration()
messageListConfiguration.setDateSeparatorStyle(dateStyle)
val messagesConfiguration = MessagesConfiguration()
messagesConfiguration.setMessageListConfiguration(messageListConfiguration)
val cometChatConversationsWithMessages: CometChatConversationsWithMessages =
view.findViewById(R.id.conversationWithMessages)
cometChatConversationsWithMessages.messagesConfiguration = messagesConfiguration