CustomTabsIntent.Builder

class 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 functions

CustomTabsIntent.Builder

This function is deprecated.

Use setShareState instead.

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

Adds a menu item.

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

This function is deprecated.

Use CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], PendingIntent).

CustomTabsIntent

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

CustomTabsIntent.Builder

This function is deprecated.

Use setUrlBarHidingEnabled instead.

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
setActionButton(
    icon: Bitmap,
    description: String,
    pendingIntent: PendingIntent,
    shouldTint: Boolean
)

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

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

Sets the Custom Tab Activity's position when acting as a side sheet.

CustomTabsIntent.Builder

Sets the Custom Tab Activity's rounded corners position when it is acting as a side sheet.

CustomTabsIntent.Builder

Enables the capability of the interaction with background.

CustomTabsIntent.Builder

Enables or disables the bookmarks button in the overflow menu.

CustomTabsIntent.Builder

Sets the Close button icon for the custom tab.

CustomTabsIntent.Builder

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(
    colorScheme: Int,
    params: CustomTabColorSchemeParams
)

Sets CustomTabColorSchemeParams for the given color scheme.

CustomTabsIntent.Builder

Sets the default CustomTabColorSchemeParams.

CustomTabsIntent.Builder

This function is deprecated.

Use setShareState instead.

CustomTabsIntent.Builder

Enables or disables the download button in the overflow menu.

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

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(
    initialHeightPx: @Dimension(unit = 1) Int,
    activityHeightResizeBehavior: Int
)

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

Sets whether Instant Apps is enabled for this Custom Tab.

CustomTabsIntent.Builder

This function is deprecated.

Use setDefaultColorSchemeParams instead.

CustomTabsIntent.Builder

This function is deprecated.

Use setDefaultColorSchemeParams instead.

CustomTabsIntent.Builder

This function is deprecated.

Use setDefaultColorSchemeParams instead.

CustomTabsIntent.Builder

Sets the PendingIntent to be sent when the user swipes up from the secondary (bottom) toolbar.

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

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

CustomTabsIntent.Builder

Enables sending initial urls to external handler apps, if possible.

CustomTabsIntent.Builder

Associates the Intent with the given CustomTabsSession.

CustomTabsIntent.Builder

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
setStartAnimations(
    context: Context,
    enterResId: @AnimRes Int,
    exitResId: @AnimRes Int
)

Sets the start animations.

CustomTabsIntent.Builder

This function is deprecated.

Use setDefaultColorSchemeParams instead.

CustomTabsIntent.Builder
setToolbarCornerRadiusDp(cornerRadiusDp: @Dimension(unit = 0) Int)

Sets the toolbar's top corner radii in dp.

CustomTabsIntent.Builder

Specifies the target locale the Translate UI should be triggered with.

CustomTabsIntent.Builder

Set whether the url bar should hide as the user scrolls down on the page.

Public constructors

Builder

Added in 1.2.0
Builder()

Creates a CustomTabsIntent.Builder object associated with no CustomTabsSession.

Builder

Added in 1.2.0
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

addDefaultShareMenuItem

Added in 1.2.0
Deprecated in 1.3.0
fun addDefaultShareMenuItem(): CustomTabsIntent.Builder

Adds a default share item to the menu.

addMenuItem

Added in 1.2.0
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.

addToolbarItem

Added in 1.2.0
Deprecated in 1.2.0
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 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.

build

Added in 1.2.0
fun build(): CustomTabsIntent

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

enableUrlBarHiding

Added in 1.2.0
Deprecated in 1.3.0
fun enableUrlBarHiding(): CustomTabsIntent.Builder

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

setActionButton

Added in 1.2.0
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

Added in 1.2.0
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

Added in 1.8.0
fun setActivitySideSheetBreakpointDp(breakpointDp: @Dimension(unit = 0) Int): CustomTabsIntent.Builder

Sets the Custom Tab Activity's transition breakpoint in DP.

Parameters
breakpointDp: @Dimension(unit = 0) Int

The Custom Tab Activity's breakpoint in DP.

setActivitySideSheetDecorationType

Added in 1.8.0
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

Added in 1.8.0
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

Added in 1.8.0
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

Added in 1.8.0
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

Added in 1.7.0
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.

setBookmarksButtonEnabled

Added in 1.7.0
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.

setCloseButtonIcon

Added in 1.2.0
fun setCloseButtonIcon(icon: Bitmap): CustomTabsIntent.Builder

Sets the Close button icon for the custom tab.

Parameters
icon: Bitmap

The icon Bitmap

setCloseButtonPosition

Added in 1.5.0
fun setCloseButtonPosition(position: Int): CustomTabsIntent.Builder

Sets the position of the close button.

Parameters
position: Int

The desired position.

setColorScheme

Added in 1.2.0
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

Added in 1.2.0
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 setColorScheme). It should not be COLOR_SCHEME_SYSTEM, because that represents a behavior rather than a particular color scheme.

params: CustomTabColorSchemeParams

An instance of CustomTabColorSchemeParams.

setDefaultColorSchemeParams

Added in 1.3.0
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 CustomTabColorSchemeParams.

setDefaultShareMenuItemEnabled

Added in 1.3.0
Deprecated in 1.3.0
fun setDefaultShareMenuItemEnabled(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

Added in 1.7.0
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.

setExitAnimations

Added in 1.2.0
fun setExitAnimations(
    context: Context,
    enterResId: @AnimRes Int,
    exitResId: @AnimRes Int
): CustomTabsIntent.Builder

Sets the exit animations.

Parameters
context: Context

Application context.

enterResId: @AnimRes Int

Resource ID of the "enter" animation for the application.

exitResId: @AnimRes Int

Resource ID of the "exit" animation for the browser.

setInitialActivityHeightPx

Added in 1.5.0
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.

setInitialActivityHeightPx

Added in 1.5.0
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.

Parameters
initialHeightPx: @Dimension(unit = 1) Int

The Custom Tab Activity's initial height in pixels.

activityHeightResizeBehavior: Int

Desired height behavior.

setInitialActivityWidthPx

Added in 1.8.0
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.

setInstantAppsEnabled

Added in 1.2.0
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.

setNavigationBarColor

Added in 1.2.0
Deprecated in 1.3.0
fun setNavigationBarColor(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.

Parameters
color: @ColorInt Int

The color for the navigation bar.

setNavigationBarDividerColor

Added in 1.3.0
Deprecated in 1.3.0
fun setNavigationBarDividerColor(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.

Parameters
color: @ColorInt Int

The color for the navigation bar divider.

setSecondaryToolbarColor

Added in 1.2.0
Deprecated in 1.3.0
fun setSecondaryToolbarColor(color: @ColorInt Int): CustomTabsIntent.Builder

Sets the color of the secondary toolbar. Can be overridden for particular color schemes, see setColorSchemeParams.

Parameters
color: @ColorInt Int

The color for the secondary toolbar.

setSecondaryToolbarSwipeUpGesture

Added in 1.7.0
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 PendingIntent that will be sent when the user swipes up from the secondary toolbar.

setSecondaryToolbarViews

Added in 1.2.0
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: IntArray?

The IDs of clickable views. The onClick event of these views will be handled by custom tabs.

pendingIntent: PendingIntent?

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.

setSendToExternalDefaultHandlerEnabled

Added in 1.7.0
fun setSendToExternalDefaultHandlerEnabled(enabled: Boolean): CustomTabsIntent.Builder

Enables sending initial urls to external handler apps, if possible.

Parameters
enabled: Boolean

Whether to send urls to external handler.

setSession

Added in 1.2.0
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

Added in 1.7.0
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

Added in 1.3.0
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

Added in 1.2.0
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

Added in 1.2.0
fun setStartAnimations(
    context: Context,
    enterResId: @AnimRes Int,
    exitResId: @AnimRes Int
): CustomTabsIntent.Builder

Sets the start animations.

Parameters
context: Context

Application context.

enterResId: @AnimRes Int

Resource ID of the "enter" animation for the browser.

exitResId: @AnimRes Int

Resource ID of the "exit" animation for the application.

setToolbarColor

Added in 1.2.0
Deprecated in 1.3.0
fun setToolbarColor(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.

Parameters
color: @ColorInt Int

Color

setToolbarCornerRadiusDp

Added in 1.5.0
fun setToolbarCornerRadiusDp(cornerRadiusDp: @Dimension(unit = 0) Int): CustomTabsIntent.Builder

Sets the toolbar's top corner radii in dp.

Parameters
cornerRadiusDp: @Dimension(unit = 0) Int

The toolbar's top corner radii in dp.

setTranslateLocale

Added in 1.7.0
fun setTranslateLocale(locale: Locale): CustomTabsIntent.Builder

Specifies the target locale the Translate UI should be triggered with.

Parameters
locale: Locale

Locale object that represents the target locale.

setUrlBarHidingEnabled

Added in 1.3.0
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.