Customize Chat Message Bubble

When framework is integrated to your app with the UI implementation method, you can add customized chat message bubbles to be used in chat.

Adding a Custom Chat Bubble

You can check the following example to add a custom bubble to your chat.

Note: To add a custom bubble, you need to implement recyclerView dependency to your app-level build.gradle file.

implementation ''

1. Create an XML layout file for the custom bubble

First, create a new XML layout resource file for your custom bubble, we will name it my_custom_bubble_layout.xml. You are free to customize the custom bubble layout as you wish. In this example, we will be using a simple image and text bubble.

<?xml version="1.0" encoding="utf-8"?>

        app:layout_constraintTop_toTopOf="parent" />
    <!--We are using TapTalk'io's default message body style for this TextView-->
        tools:text="Message body" />


Note:'s default message bubble layouts generally have a 8dp bottom margin and no top margin.

2. Create a custom listener

In order to listen to event callbacks that happens in your custom bubble, we will create a custom interface that extends TapTalkBaseCustomInterface. We will name this interface MyCustomBubbleListener.

import io.taptalk.TapTalk.Interface.TapTalkBaseCustomInterface;
import io.taptalk.TapTalk.Model.TAPMessageModel;

public interface MyCustomBubbleListener extends TapTalkBaseCustomInterface {

    // Use this to notify that the user tapped your custom bubble
    void onBubbleTapped(TAPMessageModel message);

3. Create a custom bubble ViewHolder

To display your custom bubble layout in a chat room, you will need to create a custom ViewHolder that extends TAPBaseChatViewHolder. We will name this class MyCustomBubbleViewHolder.

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import io.taptalk.TapTalk.Model.TAPMessageModel;
import io.taptalk.TapTalk.View.Adapter.TAPBaseChatViewHolder;

public class MyCustomBubbleViewHolder extends TAPBaseChatViewHolder {

    private ImageView imageView;
    private TextView textView;

    private MyCustomBubbleListener listener; // The listener that you just created above will be used here

    // Add MyCustomBubbleListener to the constructor parameter
    MyCustomBubbleViewHolder(ViewGroup parent, int itemLayoutId, MyCustomBubbleListener listener) {
        super(parent, itemLayoutId);

        // Bind views on constructor
        imageView = itemView.findViewById(;
        textView = itemView.findViewById(;

        // Pass the listener from parameter
        this.listener = listener;

    protected void onBind(TAPMessageModel message, int index) {
        super.onBind(message, index);

        // Set message text

        // Set click listener
        imageView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                // Trigger listener and pass the clicked message

4. Create a custom bubble class

Using all the things you have created above, we will create a custom bubble class that extends TAPBaseCustomBubble. This class instance will then be added to the custom bubble list.

import android.view.ViewGroup;

import io.taptalk.TapTalk.Helper.TAPBaseCustomBubble;
import io.taptalk.TapTalk.Model.TAPUserModel;
import io.taptalk.TapTalk.View.Adapter.TAPMessageAdapter;

public class MyCustomBubbleClass extends TAPBaseCustomBubble<MyCustomBubbleViewHolder, MyCustomBubbleListener> {

    public MyCustomBubbleClass(int customBubbleLayoutRes, int messageType, MyCustomBubbleListener listener) {
        super(customBubbleLayoutRes, messageType, listener);

    public MyCustomBubbleViewHolder createCustomViewHolder(ViewGroup viewGroup, TAPMessageAdapter tapMessageAdapter, TAPUserModel tapUserModel, MyCustomBubbleListener listener) {
        return new MyCustomBubbleViewHolder(viewGroup, getCustomBubbleLayoutRes(), listener);

5. Add your custom bubble class

To add your custom bubble to, use the TapUI class and call the addCustomBubble() method. This is typically done in your Application class, after init() has already been called.


// Insert the XML layout resource, message type, and your custom listener as parameter
TapUI.getInstance().addCustomBubble(new MyCustomBubbleClass(R.layout.my_custom_bubble_layout, 3001, new MyCustomBubbleListener() {
    public void onBubbleTapped(TAPMessageModel message) {
        // My custom bubble was tapped by user

Note: Please note that the message type for custom bubbles should start with 3 as the prefix. For more information, check the message type page.

After completing all the steps above, your custom bubble will be ready to use.

Showing Your Custom Bubble in Chat

You can use your customized chat bubble in a chat room by constructing a custom TAPMessageModel with constructTapTalkMessageModel() method, then sending the constructed message to the chat room with sendCustomMessage(). Both methods can be accessed from the TapCoreMessageManager class.

To construct a message, you are required to have a TAPRoomModel as a parameter. You can use getPersonalChatRoom() or getGroupChatRoom() method in TapCoreChatRoomManager class to obtain a chat room model.

Below is an example to send a custom message with the steps mentioned above.

// First, we will retrieve a TAPRoomModel required to construct a message
TapCoreChatRoomManager.getInstance().getPersonalChatRoom(RECIPIENT_USER, new TapCoreGetRoomListener() {
    public void onSuccess(TAPRoomModel room) {
        // Retrieved room data successfully, we will use this room to construct a TAPMessageModel
        TAPMessageModel customBubbleMessage = TapCoreMessageManager.getInstance().constructTapTalkMessageModel(
                "This is a custom message", // MESSAGE_BODY
                room,                       // ROOM
                3001,                       // MESSAGE_TYPE
                null                        // MESSAGE_DATA
        // We will then send the constructed message to its corresponding chat room
        TapCoreMessageManager.getInstance().sendCustomMessage(customBubbleMessage, new TapCoreSendMessageListener() {
            public void onSuccess(TAPMessageModel message) {
                // Custom message was sent successfully

            public void onError(String errorCode, String errorMessage) {

Last updated