CustomTabsIntent.Builder
class CustomTabsIntent.Builder
Builder class for CustomTabsIntent objects.
Summary
Public constructors |
|---|
Builder()Creates a |
Builder(session: CustomTabsSession?)Creates a |
Public functions |
|
|---|---|
CustomTabsIntent.Builder |
Adds a custom content action that can be invoked by the user on specific content types (image or link) within the Custom Tab. |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
addMenuItem(label: String, pendingIntent: PendingIntent)Adds a menu item. |
CustomTabsIntent.Builder |
This function is deprecated. Use CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent). |
CustomTabsIntent |
build()Combines all the options that have been set and returns a new |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
setActionButton(Sets the action button that is displayed in the Toolbar with default tinting behavior. |
CustomTabsIntent.Builder |
setActionButton(Sets the action button that is displayed in the Toolbar. |
CustomTabsIntent.Builder |
setActivitySideSheetBreakpointDp(breakpointDp: @Dimension(unit = 0) Int)Sets the Custom Tab Activity's transition breakpoint in DP. |
CustomTabsIntent.Builder |
setActivitySideSheetDecorationType(decorationType: Int)Sets the Custom Tab Activity's decoration type that will be displayed when it is acting as a side sheet. |
CustomTabsIntent.Builder |
Enables or disables the maximization button for when the Custom Tab Activity is acting as a side sheet. |
CustomTabsIntent.Builder |
setActivitySideSheetPosition(position: Int)Sets the Custom Tab Activity's position when acting as a side sheet. |
CustomTabsIntent.Builder |
setActivitySideSheetRoundedCornersPosition(roundedCornersPosition: Int)Sets the Custom Tab Activity's rounded corners position when it is acting as a side sheet. |
CustomTabsIntent.Builder |
setBackgroundInteractionEnabled(enabled: Boolean)Enables the capability of the interaction with background. |
CustomTabsIntent.Builder |
setBookmarksButtonEnabled(enabled: Boolean)Enables or disables the bookmarks button in the overflow menu. |
CustomTabsIntent.Builder |
setCloseButtonEnabled(enabled: Boolean)Sets whether to enable the close button for custom tab. |
CustomTabsIntent.Builder |
setCloseButtonIcon(icon: Bitmap)Sets the Close button icon for the custom tab. |
CustomTabsIntent.Builder |
setCloseButtonPosition(position: Int)Sets the position of the close button. |
CustomTabsIntent.Builder |
setColorScheme(colorScheme: Int)Sets the color scheme that should be applied to the user interface in the custom tab. |
CustomTabsIntent.Builder |
setColorSchemeParams(Sets |
CustomTabsIntent.Builder |
Sets the default |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
setDownloadButtonEnabled(enabled: Boolean)Enables or disables the download button in the overflow menu. |
CustomTabsIntent.Builder |
setEphemeralBrowsingEnabled(enabled: Boolean)Sets whether to enable ephemeral browsing within the Custom Tab. |
CustomTabsIntent.Builder |
Sets the exit animations. |
CustomTabsIntent.Builder |
setInitialActivityHeightPx(initialHeightPx: @Dimension(unit = 1) Int)Sets the Custom Tab Activity's initial height in pixels with default resize behavior. |
CustomTabsIntent.Builder |
setInitialActivityHeightPx(Sets the Custom Tab Activity's initial height in pixels and the desired resize behavior. |
CustomTabsIntent.Builder |
setInitialActivityWidthPx(initialWidthPx: @Dimension(unit = 1) Int)Sets the Custom Tab Activity's initial width in pixels. |
CustomTabsIntent.Builder |
@ExperimentalInitialNavigationCanLeaveBrowserAllows the Custom Tab to forward the initial URL sent to the Custom Tab to the default handling app for that URL instead of loading it (including following any redirects) in the Custom Tab. |
CustomTabsIntent.Builder |
setInstantAppsEnabled(enabled: Boolean)Sets whether Instant Apps is enabled for this Custom Tab. |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
setNetwork(network: Network)Sets the target network |
CustomTabsIntent.Builder |
setOpenInBrowserButtonState(openInBrowserState: Int)Sets the state for the Open in Browser button in the toolbar for this Custom Tab. |
CustomTabsIntent.Builder |
Associates the |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
setSecondaryToolbarSwipeUpGesture(pendingIntent: PendingIntent?)Sets the |
CustomTabsIntent.Builder |
setSecondaryToolbarViews(Sets the remote views displayed in the secondary toolbar in a custom tab. |
CustomTabsIntent.Builder |
Enables sending any redirects off of the initial URL sent to the Custom Tab to default handling apps. |
CustomTabsIntent.Builder |
setSession(session: CustomTabsSession)Associates the |
CustomTabsIntent.Builder |
setShareIdentityEnabled(enabled: Boolean)Allow Custom Tabs to obtain the caller's identity i.e. package name. |
CustomTabsIntent.Builder |
setShareState(shareState: Int)Sets the share state that should be applied to the custom tab. |
CustomTabsIntent.Builder |
setShowTitle(showTitle: Boolean)Sets whether the title should be shown in the custom tab. |
CustomTabsIntent.Builder |
Sets the start animations. |
CustomTabsIntent.Builder |
This function is deprecated. Use |
CustomTabsIntent.Builder |
setToolbarCornerRadiusDp(cornerRadiusDp: @Dimension(unit = 0) Int)Sets the toolbar's top corner radii in dp. |
CustomTabsIntent.Builder |
setTranslateLocale(locale: Locale)Specifies the target locale the Translate UI should be triggered with. |
CustomTabsIntent.Builder |
setUrlBarHidingEnabled(enabled: Boolean)Set whether the url bar should hide as the user scrolls down on the page. |
Public constructors
Builder
Builder()
Creates a CustomTabsIntent.Builder object associated with no CustomTabsSession.
Builder
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 functions
addCustomContentAction
@ExperimentalCustomContentAction
fun addCustomContentAction(action: CustomContentAction): CustomTabsIntent.Builder
Adds a custom content action that can be invoked by the user on specific content types (image or link) within the Custom Tab.
The number of actions shown to the user is at the browser's discretion. The browser may choose not to display all the actions provided. Additionally, priority will be based on the order the actions were added, with the earliest added action being given the highest priority.
When the user triggers this action, the browser will send the getPendingIntent associated with this action. The Intent within the PendingIntent will include the current URL of the Custom Tab as its data, EXTRA_TRIGGERED_CUSTOM_CONTENT_ACTION_ID with the ID of this action, EXTRA_CLICKED_CONTENT_TARGET_TYPE with the type of content interacted with, and potentially other contextual extras (e.g., EXTRA_CONTEXT_IMAGE_URL).
| Parameters | |
|---|---|
action: CustomContentAction |
The |
| Returns | |
|---|---|
CustomTabsIntent.Builder |
This Builder. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if an action with the same ID has already been added. |
addMenuItem
fun addMenuItem(label: String, pendingIntent: PendingIntent): CustomTabsIntent.Builder
Adds a menu item.
| Parameters | |
|---|---|
label: String |
Menu label. |
pendingIntent: PendingIntent |
Pending intent delivered when the menu item is clicked. |
funaddToolbarItem(
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 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: Bitmap |
The icon. |
description: String |
The description for the button. To be used for accessibility. |
pendingIntent: PendingIntent |
The pending intent delivered when the button is clicked. |
| See also | |
|---|---|
getMaxToolbarItems |
build
fun build(): CustomTabsIntent
Combines all the options that have been set and returns a new CustomTabsIntent object.
funenableUrlBarHiding(): CustomTabsIntent.Builder
Enables the url bar to hide as the user scrolls down on the page.
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.
| See also | |
|---|---|
setActionButton |
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 addToolbarItem with TOOLBAR_ACTION_BUTTON_ID as id.
| Parameters | |
|---|---|
icon: Bitmap |
The icon. |
description: String |
The description for the button. To be used for accessibility. |
pendingIntent: PendingIntent |
pending intent delivered when the button is clicked. |
shouldTint: Boolean |
Whether the action button should be tinted.. |
| See also | |
|---|---|
addToolbarItem |
setActivitySideSheetBreakpointDp
fun setActivitySideSheetBreakpointDp(breakpointDp: @Dimension(unit = 0) Int): CustomTabsIntent.Builder
Sets the Custom Tab Activity's transition breakpoint in DP.
setActivitySideSheetDecorationType
fun setActivitySideSheetDecorationType(decorationType: Int): CustomTabsIntent.Builder
Sets the Custom Tab Activity's decoration type that will be displayed when it is acting as a side sheet.
| Parameters | |
|---|---|
decorationType: Int |
The Custom Tab Activity's decoration type. |
setActivitySideSheetMaximizationEnabled
fun setActivitySideSheetMaximizationEnabled(enabled: Boolean): CustomTabsIntent.Builder
Enables or disables the maximization button for when the Custom Tab Activity is acting as a side sheet. The button is disabled by default.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the maximization button is enabled. |
setActivitySideSheetPosition
fun setActivitySideSheetPosition(position: Int): CustomTabsIntent.Builder
Sets the Custom Tab Activity's position when acting as a side sheet.
| Parameters | |
|---|---|
position: Int |
The Custom Tab Activity's position. |
setActivitySideSheetRoundedCornersPosition
fun setActivitySideSheetRoundedCornersPosition(roundedCornersPosition: Int): CustomTabsIntent.Builder
Sets the Custom Tab Activity's rounded corners position when it is acting as a side sheet.
| Parameters | |
|---|---|
roundedCornersPosition: Int |
The Custom Tab Activity's rounded corners position. |
setBackgroundInteractionEnabled
fun setBackgroundInteractionEnabled(enabled: Boolean): CustomTabsIntent.Builder
Enables the capability of the interaction with background. Enables the interactions with the background app when a Partial Custom Tab is launched.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the background interaction is enabled. |
| See also | |
|---|---|
EXTRA_DISABLE_BACKGROUND_INTERACTION |
setBookmarksButtonEnabled
fun setBookmarksButtonEnabled(enabled: Boolean): CustomTabsIntent.Builder
Enables or disables the bookmarks button in the overflow menu. The button is enabled by default.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the start button is enabled. |
| See also | |
|---|---|
EXTRA_DISABLE_BOOKMARKS_BUTTON |
setCloseButtonEnabled
fun setCloseButtonEnabled(enabled: Boolean): CustomTabsIntent.Builder
Sets whether to enable the close button for custom tab. The close button is enabled by default. If the close button is disabled, calls to setCloseButtonIcon or setCloseButtonPosition have no effect.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the close button is enabled. |
| See also | |
|---|---|
EXTRA_CLOSE_BUTTON_ENABLED |
setCloseButtonIcon
fun setCloseButtonIcon(icon: Bitmap): CustomTabsIntent.Builder
Sets the Close button icon for the custom tab. If the close button is disabled (see setCloseButtonEnabled), then calling this function has no effect.
setCloseButtonPosition
fun setCloseButtonPosition(position: Int): CustomTabsIntent.Builder
Sets the position of the close button. If the close button is disabled (see setCloseButtonEnabled), then calling this function has no effect.
| Parameters | |
|---|---|
position: Int |
The desired position. |
setColorScheme
fun setColorScheme(colorScheme: Int): CustomTabsIntent.Builder
Sets the color scheme that should be applied to the user interface in the custom tab.
| Parameters | |
|---|---|
colorScheme: Int |
Desired color scheme. |
setColorSchemeParams
fun setColorSchemeParams(
colorScheme: Int,
params: CustomTabColorSchemeParams
): CustomTabsIntent.Builder
Sets CustomTabColorSchemeParams for the given color scheme. This allows specifying two different toolbar colors for light and dark schemes. It can be useful if COLOR_SCHEME_SYSTEM is set: Custom Tabs will follow the system settings and apply the corresponding CustomTabColorSchemeParams "on the fly" when the settings change. If there is no CustomTabColorSchemeParams for the current scheme, or a particular field of it is null, Custom Tabs will fall back to the defaults provided via setDefaultColorSchemeParams. Example:
CustomTabColorSchemeParams darkParams = new CustomTabColorSchemeParams.Builder() .setToolbarColor(darkColor) .build(); CustomTabColorSchemeParams otherParams = new CustomTabColorSchemeParams.Builder() .setNavigationBarColor(otherColor) .build(); CustomTabIntent intent = new CustomTabIntent.Builder() .setColorScheme(COLOR_SCHEME_SYSTEM) .setColorSchemeParams(COLOR_SCHEME_DARK, darkParams) .setDefaultColorSchemeParams(otherParams) .build();
| Parameters | |
|---|---|
colorScheme: Int |
A constant representing a color scheme (see |
params: CustomTabColorSchemeParams |
An instance of |
setDefaultColorSchemeParams
fun setDefaultColorSchemeParams(params: CustomTabColorSchemeParams): CustomTabsIntent.Builder
Sets the default CustomTabColorSchemeParams. This will set a default color scheme that applies when no CustomTabColorSchemeParams specified for current color scheme via setColorSchemeParams.
| Parameters | |
|---|---|
params: CustomTabColorSchemeParams |
An instance of |
funsetDefaultShareMenuItemEnabled(enabled: Boolean): CustomTabsIntent.Builder
Set whether a default share item is added to the menu.
| Parameters | |
|---|---|
enabled: Boolean |
Whether default share item is added. |
setDownloadButtonEnabled
fun setDownloadButtonEnabled(enabled: Boolean): CustomTabsIntent.Builder
Enables or disables the download button in the overflow menu. The button is enabled by default.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the download button is enabled. |
| See also | |
|---|---|
EXTRA_DISABLE_DOWNLOAD_BUTTON |
setEphemeralBrowsingEnabled
fun setEphemeralBrowsingEnabled(enabled: Boolean): CustomTabsIntent.Builder
Sets whether to enable ephemeral browsing within the Custom Tab. If ephemeral browsing is enabled, and the browser supports it, the Custom Tab does not share cookies or other data with the browser.
| Parameters | |
|---|---|
enabled: Boolean |
Whether ephemeral browsing is enabled. |
| See also | |
|---|---|
EXTRA_ENABLE_EPHEMERAL_BROWSING |
setExitAnimations
fun setExitAnimations(
context: Context,
enterResId: @AnimRes Int,
exitResId: @AnimRes Int
): CustomTabsIntent.Builder
Sets the exit animations.
setInitialActivityHeightPx
fun setInitialActivityHeightPx(initialHeightPx: @Dimension(unit = 1) Int): CustomTabsIntent.Builder
Sets the Custom Tab Activity's initial height in pixels with default resize behavior. The Custom Tab will behave as a bottom sheet if the screen's width is smaller than the breakpoint value set by setActivitySideSheetBreakpointDp.
| See also | |
|---|---|
setInitialActivityHeightPx |
setInitialActivityHeightPx
fun setInitialActivityHeightPx(
initialHeightPx: @Dimension(unit = 1) Int,
activityHeightResizeBehavior: Int
): CustomTabsIntent.Builder
Sets the Custom Tab Activity's initial height in pixels and the desired resize behavior. The Custom Tab will behave as a bottom sheet if the screen's width is smaller than the breakpoint value set by setActivitySideSheetBreakpointDp.
setInitialActivityWidthPx
fun setInitialActivityWidthPx(initialWidthPx: @Dimension(unit = 1) Int): CustomTabsIntent.Builder
Sets the Custom Tab Activity's initial width in pixels. The Custom Tab will behave as a side sheet if the screen's width is bigger than the breakpoint value set by setActivitySideSheetBreakpointDp and the screen is big enough, see doc for EXTRA_INITIAL_ACTIVITY_WIDTH_PX.
| Parameters | |
|---|---|
initialWidthPx: @Dimension(unit = 1) Int |
The Custom Tab Activity's initial width in pixels. |
| See also | |
|---|---|
EXTRA_INITIAL_ACTIVITY_WIDTH_PX |
setInitialNavigationAllowedToLeaveBrowser
@ExperimentalInitialNavigationCanLeaveBrowser
fun setInitialNavigationAllowedToLeaveBrowser(enabled: Boolean): CustomTabsIntent.Builder
Allows the Custom Tab to forward the initial URL sent to the Custom Tab to the default handling app for that URL instead of loading it (including following any redirects) in the Custom Tab.
Note: This is not the default behavior. The default for this is to be set to false.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the initial URL sent to the custom tab should be sent to the default handling app for that URL. |
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. |
funsetNavigationBarColor(color: @ColorInt Int): CustomTabsIntent.Builder
Sets the navigation bar color. Has no effect on API versions below L. To ensure good contrast between navigation bar icons and the background, Custom Tab implementations may use SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR on Android O and above, and darken the provided color on Android L-N. Can be overridden for particular color schemes, see setColorSchemeParams.
funsetNavigationBarDividerColor(color: @ColorInt Int): CustomTabsIntent.Builder
Sets the navigation bar divider color. Has no effect on API versions below P. Can be overridden for particular color schemes, see setColorSchemeParams.
setNetwork
fun setNetwork(network: Network): CustomTabsIntent.Builder
Sets the target network Network to bind when launching a custom tab. This API allows the caller to specify the target network to bind when launching a URL via Custom Tabs, e.g. may want to open a custom tab over a Wi-Fi network, while the default network is a cellular connection. All URLRequests created in the future via this tab will be bound to Network. If the browser does not support this feature it will be ignored and a Custom Tab will be opened using the default network. Check the support by calling isSetNetworkSupported.
| See also | |
|---|---|
EXTRA_NETWORK |
setOpenInBrowserButtonState
fun setOpenInBrowserButtonState(openInBrowserState: Int): CustomTabsIntent.Builder
Sets the state for the Open in Browser button in the toolbar for this Custom Tab.
| Parameters | |
|---|---|
openInBrowserState: Int |
Desired Open in Browser state. |
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
when an invalid option is provided. |
setPendingSession
fun setPendingSession(session: CustomTabsSession.PendingSession): CustomTabsIntent.Builder
Associates the Intent with the given CustomTabsSession.PendingSession. Overrides the effect of setSession.
funsetSecondaryToolbarColor(color: @ColorInt Int): CustomTabsIntent.Builder
Sets the color of the secondary toolbar. Can be overridden for particular color schemes, see setColorSchemeParams.
setSecondaryToolbarSwipeUpGesture
fun setSecondaryToolbarSwipeUpGesture(pendingIntent: PendingIntent?): CustomTabsIntent.Builder
Sets the PendingIntent to be sent when the user swipes up from the secondary (bottom) toolbar.
| Parameters | |
|---|---|
pendingIntent: PendingIntent? |
The |
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 |
clickableIDs: IntArray? |
The IDs of clickable views. The onClick event of these views will be handled by custom tabs. |
pendingIntent: PendingIntent? |
The |
setSendToExternalDefaultHandlerEnabled
fun setSendToExternalDefaultHandlerEnabled(enabled: Boolean): CustomTabsIntent.Builder
Enables sending any redirects off of the initial URL sent to the Custom Tab to default handling apps. Unless #EXTRA_INITIAL_NAVIGATION_CAN_LEAVE_BROWSER is also set, the initial URL will still always load in the Custom Tab.
| Parameters | |
|---|---|
enabled: Boolean |
Whether to send urls to external handler. |
setSession
fun setSession(session: CustomTabsSession): CustomTabsIntent.Builder
Associates the Intent with the given CustomTabsSession. Guarantees that the Intent will be sent to the same component as the one the session is associated with.
setShareIdentityEnabled
fun setShareIdentityEnabled(enabled: Boolean): CustomTabsIntent.Builder
Allow Custom Tabs to obtain the caller's identity i.e. package name.
| Parameters | |
|---|---|
enabled: Boolean |
Whether the identity sharing is enabled. |
setShareState
fun setShareState(shareState: Int): CustomTabsIntent.Builder
Sets the share state that should be applied to the custom tab.
| Parameters | |
|---|---|
shareState: Int |
Desired share state. |
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. |
setStartAnimations
fun setStartAnimations(
context: Context,
enterResId: @AnimRes Int,
exitResId: @AnimRes Int
): CustomTabsIntent.Builder
Sets the start animations.
funsetToolbarColor(color: @ColorInt Int): CustomTabsIntent.Builder
Sets the toolbar color. On Android L and above, this color is also applied to the status bar. To ensure good contrast between status bar icons and the background, Custom Tab implementations may use SYSTEM_UI_FLAG_LIGHT_STATUS_BAR on Android M and above, and use a darkened color for the status bar on Android L. Can be overridden for particular color schemes, see setColorSchemeParams.
setToolbarCornerRadiusDp
fun setToolbarCornerRadiusDp(cornerRadiusDp: @Dimension(unit = 0) Int): CustomTabsIntent.Builder
Sets the toolbar's top corner radii in dp.
| See also | |
|---|---|
EXTRA_TOOLBAR_CORNER_RADIUS_DP |
setTranslateLocale
fun setTranslateLocale(locale: Locale): CustomTabsIntent.Builder
Specifies the target locale the Translate UI should be triggered with.
| See also | |
|---|---|
EXTRA_TRANSLATE_LANGUAGE_TAG |
setUrlBarHidingEnabled
fun setUrlBarHidingEnabled(enabled: Boolean): CustomTabsIntent.Builder
Set whether the url bar should hide as the user scrolls down on the page.
| Parameters | |
|---|---|
enabled: Boolean |
Whether url bar hiding is enabled. |