Builder

class Builder
kotlin.Any
   ↳ androidx.browser.customtabs.CustomTabsIntent.Builder

Builder class for CustomTabsIntent objects.

Summary

Public constructors

Creates a CustomTabsIntent.Builder object associated with no CustomTabsSession.

Creates a CustomTabsIntent.Builder object associated with a given CustomTabsSession.

Public methods
CustomTabsIntent.Builder!

Adds a default share item to the menu.

CustomTabsIntent.Builder!
setActionButton(icon: Bitmap, description: String, pendingIntent: PendingIntent, shouldTint: Boolean)

Sets the action button that is displayed in the Toolbar.

CustomTabsIntent.Builder!
setActionButton(icon: Bitmap, description: String, pendingIntent: PendingIntent)

Sets the action button that is displayed in the Toolbar with default tinting behavior.

CustomTabsIntent.Builder!
addToolbarItem(id: Int, icon: Bitmap, description: String, pendingIntent: PendingIntent!)

Adds an action button to the custom tab.

CustomTabsIntent.Builder!
setSecondaryToolbarViews(remoteViews: RemoteViews, clickableIDs: IntArray?, pendingIntent: PendingIntent?)

Sets the remote views displayed in the secondary toolbar in a custom tab.

CustomTabsIntent.Builder!

Sets the color of the secondary toolbar.

CustomTabsIntent.Builder!

Sets the Close button icon for the custom tab.

CustomTabsIntent.Builder!
setExitAnimations(context: Context, enterResId: Int, exitResId: Int)

Sets the exit animations.

CustomTabsIntent.Builder!
setShowTitle(showTitle: Boolean)

Sets whether the title should be shown in the custom tab.

CustomTabsIntent!

Combines all the options that have been set and returns a new CustomTabsIntent object.

CustomTabsIntent.Builder!

Sets whether Instant Apps is enabled for this Custom Tab.

CustomTabsIntent.Builder!

Enables the url bar to hide as the user scrolls down on the page.

CustomTabsIntent.Builder!
setStartAnimations(context: Context, enterResId: Int, exitResId: Int)

Sets the start animations.

CustomTabsIntent.Builder!

Sets the toolbar color.

CustomTabsIntent.Builder!
addMenuItem(label: String, pendingIntent: PendingIntent)

Adds a menu item.

Public constructors

<init>

Builder()

Creates a CustomTabsIntent.Builder object associated with no CustomTabsSession.

<init>

Builder(session: CustomTabsSession?)

Creates a CustomTabsIntent.Builder object associated with a given CustomTabsSession. Guarantees that the Intent will be sent to the same component as the one the session is associated with.

Parameters
session CustomTabsSession?: The session to associate this Builder with.

Public methods

addDefaultShareMenuItem

fun addDefaultShareMenuItem(): CustomTabsIntent.Builder!

Adds a default share item to the menu.

setActionButton

fun setActionButton(icon: Bitmap, description: String, pendingIntent: PendingIntent, shouldTint: Boolean): CustomTabsIntent.Builder!

Sets the action button that is displayed in the Toolbar.

This is equivalent to calling CustomTabsIntent.Builder#addToolbarItem(int, Bitmap, String, PendingIntent) with #TOOLBAR_ACTION_BUTTON_ID as id.

Parameters
icon Bitmap: The icon.
description Bitmap: The description for the button. To be used for accessibility.
pendingIntent Bitmap: pending intent delivered when the button is clicked.
shouldTint Bitmap: Whether the action button should be tinted.

setActionButton

fun setActionButton(icon: Bitmap, description: String, pendingIntent: PendingIntent): CustomTabsIntent.Builder!

Sets the action button that is displayed in the Toolbar with default tinting behavior.

addToolbarItem

fun addToolbarItem(id: Int, icon: Bitmap, description: String, pendingIntent: PendingIntent!): CustomTabsIntent.Builder!

Adds an action button to the custom tab. Multiple buttons can be added via this method. If the given id equals #TOOLBAR_ACTION_BUTTON_ID, the button will be placed on the toolbar; if the bitmap is too wide, it will be put to the bottom bar instead. If the id is not #TOOLBAR_ACTION_BUTTON_ID, it will be directly put on secondary toolbar. The maximum number of allowed toolbar items in a single intent is CustomTabsIntent#getMaxToolbarItems(). Throws an IllegalStateException when that number is exceeded per intent.

Parameters
id Int: The unique id of the action button. This should be non-negative.
icon Int: The icon.
description Int: The description for the button. To be used for accessibility.
pendingIntent Int: The pending intent delivered when the button is clicked.

setSecondaryToolbarViews

fun setSecondaryToolbarViews(remoteViews: RemoteViews, clickableIDs: IntArray?, pendingIntent: PendingIntent?): CustomTabsIntent.Builder!

Sets the remote views displayed in the secondary toolbar in a custom tab.

Parameters
remoteViews RemoteViews: The RemoteViews that will be shown on the secondary toolbar.
clickableIDs RemoteViews: The IDs of clickable views. The onClick event of these views will be handled by custom tabs.
pendingIntent RemoteViews: The PendingIntent that will be sent when the user clicks on one of the Views in clickableIDs. When the PendingIntent is sent, it will have the current URL as its intent data.

setSecondaryToolbarColor

fun setSecondaryToolbarColor(color: Int): CustomTabsIntent.Builder!

Sets the color of the secondary toolbar.

Parameters
color Int: The color for the secondary toolbar.

setCloseButtonIcon

fun setCloseButtonIcon(icon: Bitmap): CustomTabsIntent.Builder!

Sets the Close button icon for the custom tab.

Parameters
icon Bitmap: The icon Bitmap

setExitAnimations

fun setExitAnimations(context: Context, enterResId: Int, exitResId: Int): CustomTabsIntent.Builder!

Sets the exit animations.

Parameters
context Context: Application context.
enterResId Context: Resource ID of the "enter" animation for the application.
exitResId Context: Resource ID of the "exit" animation for the browser.

setShowTitle

fun setShowTitle(showTitle: Boolean): CustomTabsIntent.Builder!

Sets whether the title should be shown in the custom tab.

Parameters
showTitle Boolean: Whether the title should be shown.

build

fun build(): CustomTabsIntent!

Combines all the options that have been set and returns a new CustomTabsIntent object.

setInstantAppsEnabled

fun setInstantAppsEnabled(enabled: Boolean): CustomTabsIntent.Builder!

Sets whether Instant Apps is enabled for this Custom Tab.

Parameters
enabled Boolean: Whether Instant Apps should be enabled.

enableUrlBarHiding

fun enableUrlBarHiding(): CustomTabsIntent.Builder!

Enables the url bar to hide as the user scrolls down on the page.

setStartAnimations

fun setStartAnimations(context: Context, enterResId: Int, exitResId: Int): CustomTabsIntent.Builder!

Sets the start animations.

Parameters
context Context: Application context.
enterResId Context: Resource ID of the "enter" animation for the browser.
exitResId Context: Resource ID of the "exit" animation for the application.

setToolbarColor

fun setToolbarColor(color: Int): CustomTabsIntent.Builder!

Sets the toolbar color.

Parameters
color Int: Color

addMenuItem

fun addMenuItem(label: String, pendingIntent: PendingIntent): CustomTabsIntent.Builder!

Adds a menu item.

Parameters
label String: Menu label.
pendingIntent String: Pending intent delivered when the menu item is clicked.