Skip to main content
{
  "component": "CometChatCallButtons",
  "package": "com.cometchat.chatuikit.calls.callbutton",
  "xmlElement": "<com.cometchat.chatuikit.calls.callbutton.CometChatCallButtons />",
  "description": "Voice and video call buttons that initiate calls for a given user or group.",
  "primaryOutput": {
    "method": "setOnVoiceCallClick / setOnVideoCallClick",
    "type": "OnClick"
  },
  "methods": {
    "data": {
      "setUser": {
        "type": "User",
        "default": "null",
        "note": "Sets the user to call. Required for 1-on-1 calls."
      },
      "setGroup": {
        "type": "Group",
        "default": "null",
        "note": "Sets the group to call. Required for group calls."
      }
    },
    "callbacks": {
      "setOnVoiceCallClick": "OnClick — void onClick(User user, Group group)",
      "setOnVideoCallClick": "OnClick — void onClick(User user, Group group)"
    },
    "visibility": {
      "setVoiceCallButtonVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setVideoCallButtonVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setButtonTextVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setButtonIconVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" }
    },
    "viewSlots": {
      "getVoiceCallButton": "CometChatButton — direct access to the voice call button for customization",
      "getVideoCallButton": "CometChatButton — direct access to the video call button for customization"
    },
    "advanced": {
      "setOutgoingCallConfiguration": "OutgoingCallConfiguration — configures the outgoing call screen",
      "setCallSettingsBuilder": "Function3<User, Group, Boolean, CometChatCalls.CallSettingsBuilder> — custom call settings per call type",
      "setMarginBetweenButtons": "@Dimension int — spacing between voice and video buttons",
      "setVoiceButtonText": "String — custom text for the voice call button",
      "setVideoButtonText": "String — custom text for the video call button",
      "disposeObservers": "void — removes lifecycle observers"
    },
    "style": {
      "setStyle": {
        "type": "@StyleRes int",
        "parent": "CometChatCallButtonsStyle"
      }
    }
  },
  "events": [
    {
      "name": "CometChatCallEvents.ccOutgoingCall",
      "payload": "Call",
      "description": "An outgoing call was initiated"
    },
    {
      "name": "CometChatCallEvents.ccCallAccepted",
      "payload": "Call",
      "description": "A call was accepted by the recipient"
    },
    {
      "name": "CometChatCallEvents.ccCallRejected",
      "payload": "Call",
      "description": "A call was rejected by the recipient"
    },
    {
      "name": "CometChatCallEvents.ccCallEnded",
      "payload": "Call",
      "description": "A call was ended"
    }
  ],
  "sdkListeners": []
}

Where It Fits

CometChatCallButtons is a utility component. It renders voice and video call buttons and initiates calls for the bound User or Group. Wire it into a CometChatMessageHeader or place it anywhere a call action is needed.
ChatActivity.kt
class ChatActivity : AppCompatActivity() {

    private lateinit var messageHeader: CometChatMessageHeader
    private lateinit var callButtons: CometChatCallButtons

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_chat)

        messageHeader = findViewById(R.id.message_header)
        callButtons = findViewById(R.id.call_buttons)

        // Bind the same user to both components
        val user: User = intent.getParcelableExtra("user")!!
        messageHeader.setUser(user)
        callButtons.setUser(user)
    }
}

Quick Start

Add the component to your layout XML:
layout_activity.xml
<com.cometchat.chatuikit.calls.callbutton.CometChatCallButtons
        android:id="@+id/call_buttons"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added. To add programmatically in an Activity:
YourActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val callButtons = CometChatCallButtons(this)
    callButtons.setUser(user)
    setContentView(callButtons)
}
Or in a Fragment:
YourFragment.kt
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
    val callButtons = CometChatCallButtons(requireContext())
    callButtons.setUser(user)
    return callButtons
}
You must call setUser(User) or setGroup(Group) before the buttons can initiate a call. Without a target, button clicks have no effect.

Actions and Events

Callback Methods

setOnVoiceCallClick

Fires when the voice call button is tapped. Replaces the default behavior of initiating an audio call.
YourActivity.kt
callButtons.setOnVoiceCallClick { user, group ->
    // Custom voice call logic
}
What this does: Replaces the default voice call initiation. When a user taps the voice call button, your custom lambda executes instead of the built-in call flow. The OnClick interface provides void onClick(User user, Group group).

setOnVideoCallClick

Fires when the video call button is tapped. Replaces the default behavior of initiating a video call.
YourActivity.kt
callButtons.setOnVideoCallClick { user, group ->
    // Custom video call logic
}
  • Verify: After setting a callback, tap the corresponding button and confirm your custom logic executes instead of the default call initiation.

Global UI Events (CometChatCallEvents)

CometChatCallEvents emits events subscribable from anywhere in the application. Add a listener and remove it when no longer needed.
EventFires whenPayload
ccOutgoingCallAn outgoing call is initiatedCall
ccCallAcceptedA call is accepted by the recipientCall
ccCallRejectedA call is rejected by the recipientCall
ccCallEndedA call is endedCall
Add Listener
CometChatCallEvents.addListener("CALL_LISTENER_TAG", object : CometChatCallEvents() {
    override fun ccOutgoingCall(call: Call?) {
        super.ccOutgoingCall(call)
    }

    override fun ccCallAccepted(call: Call?) {
        super.ccCallAccepted(call)
    }

    override fun ccCallRejected(call: Call?) {
        super.ccCallRejected(call)
    }

    override fun ccCallEnded(call: Call?) {
        super.ccCallEnded(call)
    }
})
Remove Listener
CometChatCallEvents.removeListener("CALL_LISTENER_TAG")

SDK Events

The component uses an internal CallButtonsViewModel that observes call initiation and direct call events. No manual SDK listener attachment is needed — the component handles call lifecycle internally.

Functionality

Small functional customizations such as toggling visibility of UI elements and configuring button spacing.
MethodDescriptionCode
setVoiceCallButtonVisibilityToggles visibility of the voice call button.setVoiceCallButtonVisibility(View.GONE);
setVideoCallButtonVisibilityToggles visibility of the video call button.setVideoCallButtonVisibility(View.GONE);
setButtonTextVisibilityToggles visibility of text labels on both buttons.setButtonTextVisibility(View.GONE);
setButtonIconVisibilityToggles visibility of icons on both buttons.setButtonIconVisibility(View.GONE);
setMarginBetweenButtonsSets the spacing between voice and video buttons.setMarginBetweenButtons(24);
  • Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden.

Custom View Slots

CometChatCallButtons exposes direct access to its two internal CometChatButton instances. Use these to customize icons, text, colors, and other properties on each button individually.
SlotMethodReturns
Voice call buttongetVoiceCallButton()CometChatButton
Video call buttongetVideoCallButton()CometChatButton
// Access the voice call button and customize it
val voiceBtn = callButtons.getVoiceCallButton()
voiceBtn.setButtonText("Audio")

// Access the video call button and customize it
val videoBtn = callButtons.getVideoCallButton()
videoBtn.setButtonText("Video")
  • Verify: After accessing a button via getVoiceCallButton() or getVideoCallButton(), confirm your customizations render correctly on the corresponding button.

Common Patterns

Video-only buttons

callButtons.setVoiceCallButtonVisibility(View.GONE)

Voice-only buttons

callButtons.setVideoCallButtonVisibility(View.GONE)

Custom button text

callButtons.setVoiceButtonText("Audio Call")
callButtons.setVideoButtonText("Video Call")

Icon-only buttons

callButtons.setButtonTextVisibility(View.GONE)

Advanced Methods

setUser / setGroup

Binds the component to a specific user or group. Required before calls can be initiated.
// For 1-on-1 calls
callButtons.setUser(user)

// For group calls
callButtons.setGroup(group)

setOutgoingCallConfiguration

Configures the outgoing call screen that appears after a call is initiated.
val config = OutgoingCallConfiguration()
callButtons.setOutgoingCallConfiguration(config)

setCallSettingsBuilder

Provides a callback to customize call settings per call. The callback receives the User, Group, and a Boolean indicating whether the call is audio (true) or video (false), and returns a CometChatCalls.CallSettingsBuilder.
callButtons.setCallSettingsBuilder { user, group, isAudio ->
    CometChatCalls.CallSettingsBuilder(this, true)
        .setIsAudioOnly(isAudio)
}

getVoiceCallButton / getVideoCallButton

Returns the internal CometChatButton instances for direct customization.
MethodReturnsDescription
getVoiceCallButton()CometChatButtonThe voice call button instance
getVideoCallButton()CometChatButtonThe video call button instance

disposeObservers

Removes lifecycle observers manually. Normally handled automatically when the view detaches from the window.
callButtons.disposeObservers()

Style

The component uses XML theme styles. Define a custom style with parent CometChatCallButtonsStyle in themes.xml, then apply with setStyle().
themes.xml
<style name="CustomCallButtonsStyle" parent="CometChatCallButtonsStyle">
    <item name="cometchatCallButtonsVoiceCallIconTint">#4CAF50</item>
    <item name="cometchatCallButtonsVideoCallIconTint">#2196F3</item>
    <item name="cometchatCallButtonsVoiceCallBackgroundColor">#E8F5E9</item>
    <item name="cometchatCallButtonsVideoCallBackgroundColor">#E3F2FD</item>
    <item name="cometchatCallButtonsMarginBetween">16dp</item>
</style>
callButtons.setStyle(R.style.CustomCallButtonsStyle)

Programmatic Style Properties

In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:
MethodTypeDescription
setVoiceCallIconDrawableIcon drawable for the voice call button
setVideoCallIconDrawableIcon drawable for the video call button
setVoiceCallIconTint@ColorInt intTint color for the voice call icon
setVideoCallIconTint@ColorInt intTint color for the video call icon
setVoiceCallTextColor@ColorInt intText color for the voice call button
setVideoCallTextColor@ColorInt intText color for the video call button
setVoiceCallTextAppearance@StyleRes intText appearance for the voice call button
setVideoCallTextAppearance@StyleRes intText appearance for the video call button
setVoiceCallBackgroundColor@ColorInt intBackground color for the voice call button
setVideoCallBackgroundColor@ColorInt intBackground color for the video call button
setVoiceCallCornerRadius@Dimension intCorner radius for the voice call button
setVideoCallCornerRadius@Dimension intCorner radius for the video call button
setVoiceCallIconSize@Dimension intIcon size for the voice call button
setVideoCallIconSize@Dimension intIcon size for the video call button
setVoiceCallStrokeWidth@Dimension intStroke width for the voice call button
setVideoCallStrokeWidth@Dimension intStroke width for the video call button
setVoiceCallStrokeColor@ColorInt intStroke color for the voice call button
setVideoCallStrokeColor@ColorInt intStroke color for the video call button
setVoiceCallButtonPadding@Dimension intPadding for the voice call button
setVideoCallButtonPadding@Dimension intPadding for the video call button

Customization Matrix

What to changeWhereProperty/APIExample
Override voice call tap behaviorActivity/FragmentsetOnVoiceCallClicksetOnVoiceCallClick((u, g) -> { ... })
Override video call tap behaviorActivity/FragmentsetOnVideoCallClicksetOnVideoCallClick((u, g) -> { ... })
Hide voice call buttonActivity/FragmentsetVoiceCallButtonVisibility(int)setVoiceCallButtonVisibility(View.GONE)
Hide video call buttonActivity/FragmentsetVideoCallButtonVisibility(int)setVideoCallButtonVisibility(View.GONE)
Hide button text labelsActivity/FragmentsetButtonTextVisibility(int)setButtonTextVisibility(View.GONE)
Hide button iconsActivity/FragmentsetButtonIconVisibility(int)setButtonIconVisibility(View.GONE)
Change button spacingActivity/FragmentsetMarginBetweenButtons(int)setMarginBetweenButtons(24)
Set custom button textActivity/FragmentsetVoiceButtonText / setVideoButtonTextsetVoiceButtonText("Audio Call")
Change voice call iconActivity/FragmentsetVoiceCallIcon(Drawable)setVoiceCallIcon(drawable)
Change video call iconActivity/FragmentsetVideoCallIcon(Drawable)setVideoCallIcon(drawable)
Change icon tint colorsActivity/FragmentsetVoiceCallIconTint / setVideoCallIconTintsetVoiceCallIconTint(Color.GREEN)
Change text colorsActivity/FragmentsetVoiceCallTextColor / setVideoCallTextColorsetVoiceCallTextColor(Color.BLACK)
Change background colorsActivity/FragmentsetVoiceCallBackgroundColor / setVideoCallBackgroundColorsetVoiceCallBackgroundColor(Color.WHITE)
Change corner radiusActivity/FragmentsetVoiceCallCornerRadius / setVideoCallCornerRadiussetVoiceCallCornerRadius(16)
Change icon sizeActivity/FragmentsetVoiceCallIconSize / setVideoCallIconSizesetVoiceCallIconSize(48)
Change stroke widthActivity/FragmentsetVoiceCallStrokeWidth / setVideoCallStrokeWidthsetVoiceCallStrokeWidth(2)
Change stroke colorActivity/FragmentsetVoiceCallStrokeColor / setVideoCallStrokeColorsetVoiceCallStrokeColor(Color.GRAY)
Change button paddingActivity/FragmentsetVoiceCallButtonPadding / setVideoCallButtonPaddingsetVoiceCallButtonPadding(12)
Apply XML theme stylethemes.xmlCometChatCallButtonsStyle<item name="cometchatCallButtonsVoiceCallIconTint">#4CAF50</item>
Apply style programmaticallyActivity/FragmentsetStyle(int styleRes)callButtons.setStyle(R.style.CustomCallButtonsStyle)
Configure outgoing call screenActivity/FragmentsetOutgoingCallConfigurationsetOutgoingCallConfiguration(config)
Custom call settings per callActivity/FragmentsetCallSettingsBuilderSee setCallSettingsBuilder code above
Access internal buttonsActivity/FragmentgetVoiceCallButton() / getVideoCallButton()callButtons.getVoiceCallButton()

Accessibility

The component renders two CometChatButton instances inside a MaterialCardView. Each button responds to tap gestures. The voice and video call icons include default content descriptions for screen readers. For custom icons set via setVoiceCallIcon or setVideoCallIcon, ensure you set android:contentDescription on the drawable or on the button view so TalkBack can announce the action. The default icons handle this automatically. Button text labels (when visible) provide additional context for assistive technologies. If you hide text with setButtonTextVisibility(View.GONE), consider adding explicit content descriptions to the buttons via getVoiceCallButton().setContentDescription(...).

Next Steps