CustomTabsIntent.Builder


public final 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 methods

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setShareState instead.

@NonNull CustomTabsIntent.Builder
addMenuItem(@NonNull String label, @NonNull PendingIntent pendingIntent)

Adds a menu item.

@NonNull CustomTabsIntent.Builder
addToolbarItem(
    int id,
    @NonNull Bitmap icon,
    @NonNull String description,
    @NonNull PendingIntent pendingIntent
)

This method is deprecated.

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

@NonNull CustomTabsIntent

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

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setUrlBarHidingEnabled instead.

@NonNull CustomTabsIntent.Builder
setActionButton(
    @NonNull Bitmap icon,
    @NonNull String description,
    @NonNull PendingIntent pendingIntent
)

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

@NonNull CustomTabsIntent.Builder
setActionButton(
    @NonNull Bitmap icon,
    @NonNull String description,
    @NonNull PendingIntent pendingIntent,
    boolean shouldTint
)

Sets the action button that is displayed in the Toolbar.

@NonNull CustomTabsIntent.Builder
setActivitySideSheetBreakpointDp(@Dimension(unit = 0) int breakpointDp)

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

@NonNull CustomTabsIntent.Builder

Sets the Custom Tab Activity's decoration type that will be displayed when it is acting as a side sheet.

@NonNull CustomTabsIntent.Builder

Enables or disables the maximization button for when the Custom Tab Activity is acting as a side sheet.

@NonNull CustomTabsIntent.Builder

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

@NonNull CustomTabsIntent.Builder
setActivitySideSheetRoundedCornersPosition(int roundedCornersPosition)

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

@NonNull CustomTabsIntent.Builder

Enables the capability of the interaction with background.

@NonNull CustomTabsIntent.Builder
setBookmarksButtonEnabled(boolean enabled)

Enables or disables the bookmarks button in the overflow menu.

@NonNull CustomTabsIntent.Builder

Sets the Close button icon for the custom tab.

@NonNull CustomTabsIntent.Builder
setCloseButtonPosition(int position)

Sets the position of the close button.

@NonNull CustomTabsIntent.Builder
setColorScheme(int colorScheme)

Sets the color scheme that should be applied to the user interface in the custom tab.

@NonNull CustomTabsIntent.Builder
setColorSchemeParams(
    int colorScheme,
    @NonNull CustomTabColorSchemeParams params
)

Sets CustomTabColorSchemeParams for the given color scheme.

@NonNull CustomTabsIntent.Builder

Sets the default CustomTabColorSchemeParams.

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setShareState instead.

@NonNull CustomTabsIntent.Builder
setDownloadButtonEnabled(boolean enabled)

Enables or disables the download button in the overflow menu.

@NonNull CustomTabsIntent.Builder
setExitAnimations(
    @NonNull Context context,
    @AnimRes int enterResId,
    @AnimRes int exitResId
)

Sets the exit animations.

@NonNull CustomTabsIntent.Builder
setInitialActivityHeightPx(@Dimension(unit = 1) int initialHeightPx)

Sets the Custom Tab Activity's initial height in pixels with default resize behavior.

@NonNull CustomTabsIntent.Builder
setInitialActivityHeightPx(
    @Dimension(unit = 1) int initialHeightPx,
    int activityHeightResizeBehavior
)

Sets the Custom Tab Activity's initial height in pixels and the desired resize behavior.

@NonNull CustomTabsIntent.Builder
setInitialActivityWidthPx(@Dimension(unit = 1) int initialWidthPx)

Sets the Custom Tab Activity's initial width in pixels.

@NonNull CustomTabsIntent.Builder
setInstantAppsEnabled(boolean enabled)

Sets whether Instant Apps is enabled for this Custom Tab.

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

@NonNull CustomTabsIntent.Builder

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

@NonNull CustomTabsIntent.Builder
setSecondaryToolbarViews(
    @NonNull RemoteViews remoteViews,
    @Nullable int[] clickableIDs,
    @Nullable PendingIntent pendingIntent
)

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

@NonNull CustomTabsIntent.Builder

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

@NonNull CustomTabsIntent.Builder

Associates the Intent with the given CustomTabsSession.

@NonNull CustomTabsIntent.Builder
setShareIdentityEnabled(boolean enabled)

Allow Custom Tabs to obtain the caller's identity i.e. package name.

@NonNull CustomTabsIntent.Builder
setShareState(int shareState)

Sets the share state that should be applied to the custom tab.

@NonNull CustomTabsIntent.Builder
setShowTitle(boolean showTitle)

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

@NonNull CustomTabsIntent.Builder
setStartAnimations(
    @NonNull Context context,
    @AnimRes int enterResId,
    @AnimRes int exitResId
)

Sets the start animations.

@NonNull CustomTabsIntent.Builder

This method is deprecated.

Use setDefaultColorSchemeParams instead.

@NonNull CustomTabsIntent.Builder
setToolbarCornerRadiusDp(@Dimension(unit = 0) int cornerRadiusDp)

Sets the toolbar's top corner radii in dp.

@NonNull CustomTabsIntent.Builder

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

@NonNull CustomTabsIntent.Builder
setUrlBarHidingEnabled(boolean enabled)

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

Public constructors

Builder

Added in 1.2.0
public Builder()

Creates a CustomTabsIntent.Builder object associated with no CustomTabsSession.

Builder

Added in 1.2.0
public Builder(@Nullable CustomTabsSession session)

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
@Nullable CustomTabsSession session

The session to associate this Builder with.

Public methods

addDefaultShareMenuItem

Added in 1.2.0
Deprecated in 1.3.0
public @NonNull CustomTabsIntent.Builder addDefaultShareMenuItem()

Adds a default share item to the menu.

addMenuItem

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder addMenuItem(@NonNull String label, @NonNull PendingIntent pendingIntent)

Adds a menu item.

Parameters
@NonNull String label

Menu label.

@NonNull PendingIntent pendingIntent

Pending intent delivered when the menu item is clicked.

addToolbarItem

Added in 1.2.0
Deprecated in 1.2.0
public @NonNull CustomTabsIntent.Builder addToolbarItem(
    int id,
    @NonNull Bitmap icon,
    @NonNull String description,
    @NonNull PendingIntent pendingIntent
)

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
int id

The unique id of the action button. This should be non-negative.

@NonNull Bitmap icon

The icon.

@NonNull String description

The description for the button. To be used for accessibility.

@NonNull PendingIntent pendingIntent

The pending intent delivered when the button is clicked.

build

Added in 1.2.0
public @NonNull CustomTabsIntent build()

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
public @NonNull CustomTabsIntent.Builder enableUrlBarHiding()

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

setActionButton

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setActionButton(
    @NonNull Bitmap icon,
    @NonNull String description,
    @NonNull PendingIntent pendingIntent
)

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

See also
setActionButton

setActionButton

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setActionButton(
    @NonNull Bitmap icon,
    @NonNull String description,
    @NonNull PendingIntent pendingIntent,
    boolean shouldTint
)

Sets the action button that is displayed in the Toolbar.

This is equivalent to calling addToolbarItem with TOOLBAR_ACTION_BUTTON_ID as id.

Parameters
@NonNull Bitmap icon

The icon.

@NonNull String description

The description for the button. To be used for accessibility.

@NonNull PendingIntent pendingIntent

pending intent delivered when the button is clicked.

boolean shouldTint

Whether the action button should be tinted..

See also
addToolbarItem

setActivitySideSheetBreakpointDp

Added in 1.8.0
public @NonNull CustomTabsIntent.Builder setActivitySideSheetBreakpointDp(@Dimension(unit = 0) int breakpointDp)

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

Parameters
@Dimension(unit = 0) int breakpointDp

The Custom Tab Activity's breakpoint in DP.

setActivitySideSheetDecorationType

Added in 1.8.0
public @NonNull CustomTabsIntent.Builder setActivitySideSheetDecorationType(int decorationType)

Sets the Custom Tab Activity's decoration type that will be displayed when it is acting as a side sheet.

Parameters
int decorationType

The Custom Tab Activity's decoration type.

setActivitySideSheetMaximizationEnabled

Added in 1.8.0
public @NonNull CustomTabsIntent.Builder setActivitySideSheetMaximizationEnabled(boolean enabled)

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
boolean enabled

Whether the maximization button is enabled.

setActivitySideSheetPosition

Added in 1.8.0
public @NonNull CustomTabsIntent.Builder setActivitySideSheetPosition(int position)

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

Parameters
int position

The Custom Tab Activity's position.

setActivitySideSheetRoundedCornersPosition

Added in 1.8.0
public @NonNull CustomTabsIntent.Builder setActivitySideSheetRoundedCornersPosition(int roundedCornersPosition)

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

Parameters
int roundedCornersPosition

The Custom Tab Activity's rounded corners position.

setBackgroundInteractionEnabled

Added in 1.7.0
public @NonNull CustomTabsIntent.Builder setBackgroundInteractionEnabled(boolean enabled)

Enables the capability of the interaction with background. Enables the interactions with the background app when a Partial Custom Tab is launched.

Parameters
boolean enabled

Whether the background interaction is enabled.

setBookmarksButtonEnabled

Added in 1.7.0
public @NonNull CustomTabsIntent.Builder setBookmarksButtonEnabled(boolean enabled)

Enables or disables the bookmarks button in the overflow menu. The button is enabled by default.

Parameters
boolean enabled

Whether the start button is enabled.

setCloseButtonIcon

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setCloseButtonIcon(@NonNull Bitmap icon)

Sets the Close button icon for the custom tab.

Parameters
@NonNull Bitmap icon

The icon Bitmap

setCloseButtonPosition

Added in 1.5.0
public @NonNull CustomTabsIntent.Builder setCloseButtonPosition(int position)

Sets the position of the close button.

Parameters
int position

The desired position.

setColorScheme

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setColorScheme(int colorScheme)

Sets the color scheme that should be applied to the user interface in the custom tab.

Parameters
int colorScheme

Desired color scheme.

setColorSchemeParams

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setColorSchemeParams(
    int colorScheme,
    @NonNull CustomTabColorSchemeParams params
)

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
int colorScheme

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.

@NonNull CustomTabColorSchemeParams params

An instance of CustomTabColorSchemeParams.

setDefaultColorSchemeParams

Added in 1.3.0
public @NonNull CustomTabsIntent.Builder setDefaultColorSchemeParams(@NonNull CustomTabColorSchemeParams params)

Sets the default CustomTabColorSchemeParams. This will set a default color scheme that applies when no CustomTabColorSchemeParams specified for current color scheme via setColorSchemeParams.

Parameters
@NonNull CustomTabColorSchemeParams params

An instance of CustomTabColorSchemeParams.

setDefaultShareMenuItemEnabled

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull CustomTabsIntent.Builder setDefaultShareMenuItemEnabled(boolean enabled)

Set whether a default share item is added to the menu.

Parameters
boolean enabled

Whether default share item is added.

setDownloadButtonEnabled

Added in 1.7.0
public @NonNull CustomTabsIntent.Builder setDownloadButtonEnabled(boolean enabled)

Enables or disables the download button in the overflow menu. The button is enabled by default.

Parameters
boolean enabled

Whether the download button is enabled.

setExitAnimations

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setExitAnimations(
    @NonNull Context context,
    @AnimRes int enterResId,
    @AnimRes int exitResId
)

Sets the exit animations.

Parameters
@NonNull Context context

Application context.

@AnimRes int enterResId

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

@AnimRes int exitResId

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

setInitialActivityHeightPx

Added in 1.5.0
public @NonNull CustomTabsIntent.Builder setInitialActivityHeightPx(@Dimension(unit = 1) int initialHeightPx)

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
public @NonNull CustomTabsIntent.Builder setInitialActivityHeightPx(
    @Dimension(unit = 1) int initialHeightPx,
    int activityHeightResizeBehavior
)

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
@Dimension(unit = 1) int initialHeightPx

The Custom Tab Activity's initial height in pixels.

int activityHeightResizeBehavior

Desired height behavior.

setInitialActivityWidthPx

Added in 1.8.0
public @NonNull CustomTabsIntent.Builder setInitialActivityWidthPx(@Dimension(unit = 1) int initialWidthPx)

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
@Dimension(unit = 1) int initialWidthPx

The Custom Tab Activity's initial width in pixels.

setInstantAppsEnabled

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setInstantAppsEnabled(boolean enabled)

Sets whether Instant Apps is enabled for this Custom Tab.

Parameters
boolean enabled

Whether Instant Apps should be enabled.

setNavigationBarColor

Added in 1.2.0
Deprecated in 1.3.0
public @NonNull CustomTabsIntent.Builder setNavigationBarColor(@ColorInt int color)

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
@ColorInt int color

The color for the navigation bar.

setNavigationBarDividerColor

Added in 1.3.0
Deprecated in 1.3.0
public @NonNull CustomTabsIntent.Builder setNavigationBarDividerColor(@ColorInt int color)

Sets the navigation bar divider color. Has no effect on API versions below P. Can be overridden for particular color schemes, see setColorSchemeParams.

Parameters
@ColorInt int color

The color for the navigation bar divider.

setSecondaryToolbarColor

Added in 1.2.0
Deprecated in 1.3.0
public @NonNull CustomTabsIntent.Builder setSecondaryToolbarColor(@ColorInt int color)

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

Parameters
@ColorInt int color

The color for the secondary toolbar.

setSecondaryToolbarSwipeUpGesture

Added in 1.7.0
public @NonNull CustomTabsIntent.Builder setSecondaryToolbarSwipeUpGesture(@Nullable PendingIntent pendingIntent)

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

Parameters
@Nullable PendingIntent pendingIntent

The PendingIntent that will be sent when the user swipes up from the secondary toolbar.

setSecondaryToolbarViews

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setSecondaryToolbarViews(
    @NonNull RemoteViews remoteViews,
    @Nullable int[] clickableIDs,
    @Nullable PendingIntent pendingIntent
)

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

Parameters
@NonNull RemoteViews remoteViews

The RemoteViews that will be shown on the secondary toolbar.

@Nullable int[] clickableIDs

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

@Nullable 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
public @NonNull CustomTabsIntent.Builder setSendToExternalDefaultHandlerEnabled(boolean enabled)

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

Parameters
boolean enabled

Whether to send urls to external handler.

setSession

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setSession(@NonNull CustomTabsSession session)

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
public @NonNull CustomTabsIntent.Builder setShareIdentityEnabled(boolean enabled)

Allow Custom Tabs to obtain the caller's identity i.e. package name.

Parameters
boolean enabled

Whether the identity sharing is enabled.

setShareState

Added in 1.3.0
public @NonNull CustomTabsIntent.Builder setShareState(int shareState)

Sets the share state that should be applied to the custom tab.

Parameters
int shareState

Desired share state.

setShowTitle

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setShowTitle(boolean showTitle)

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

Parameters
boolean showTitle

Whether the title should be shown.

setStartAnimations

Added in 1.2.0
public @NonNull CustomTabsIntent.Builder setStartAnimations(
    @NonNull Context context,
    @AnimRes int enterResId,
    @AnimRes int exitResId
)

Sets the start animations.

Parameters
@NonNull Context context

Application context.

@AnimRes int enterResId

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

@AnimRes int exitResId

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

setToolbarColor

Added in 1.2.0
Deprecated in 1.3.0
public @NonNull CustomTabsIntent.Builder setToolbarColor(@ColorInt int color)

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
@ColorInt int color

Color

setToolbarCornerRadiusDp

Added in 1.5.0
public @NonNull CustomTabsIntent.Builder setToolbarCornerRadiusDp(@Dimension(unit = 0) int cornerRadiusDp)

Sets the toolbar's top corner radii in dp.

Parameters
@Dimension(unit = 0) int cornerRadiusDp

The toolbar's top corner radii in dp.

setTranslateLocale

Added in 1.7.0
public @NonNull CustomTabsIntent.Builder setTranslateLocale(@NonNull Locale locale)

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

Parameters
@NonNull Locale locale

Locale object that represents the target locale.

setUrlBarHidingEnabled

Added in 1.3.0
public @NonNull CustomTabsIntent.Builder setUrlBarHidingEnabled(boolean enabled)

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

Parameters
boolean enabled

Whether url bar hiding is enabled.