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.

<init>(@Nullable session: 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
addMenuItem(@NonNull label: String, @NonNull pendingIntent: PendingIntent)

Adds a menu item.

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

Adds an action button to the custom tab.

CustomTabsIntent

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

CustomTabsIntent.Builder

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

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

Sets the action button that is displayed in the Toolbar.

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

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

CustomTabsIntent.Builder
setCloseButtonIcon(@NonNull icon: Bitmap)

Sets the Close button icon for the custom tab.

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, @NonNull params: CustomTabColorSchemeParams)

Sets CustomTabColorSchemeParams for the given color scheme.

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

Sets the exit animations.

CustomTabsIntent.Builder

Sets whether Instant Apps is enabled for this Custom Tab.

CustomTabsIntent.Builder

Sets the navigation bar color.

CustomTabsIntent.Builder

Sets the color of the secondary toolbar.

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

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

CustomTabsIntent.Builder
setSession(@NonNull session: CustomTabsSession)

Associates the Intent with the given CustomTabsSession.

CustomTabsIntent.Builder
setShowTitle(showTitle: Boolean)

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

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

Sets the start animations.

CustomTabsIntent.Builder

Sets the toolbar color.

Public constructors

<init>

Builder()

Creates a CustomTabsIntent.Builder object associated with no CustomTabsSession.

<init>

Builder(@Nullable 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

@NonNull fun addDefaultShareMenuItem(): CustomTabsIntent.Builder

Adds a default share item to the menu.

addMenuItem

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

Adds a menu item.

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

addToolbarItem

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

Deprecated: Use CustomTabsIntent.Builder#setSecondaryToolbarViews(RemoteViews, int[], 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 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.

build

@NonNull fun build(): CustomTabsIntent

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

enableUrlBarHiding

@NonNull fun enableUrlBarHiding(): CustomTabsIntent.Builder

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

setActionButton

@NonNull fun setActionButton(@NonNull icon: Bitmap, @NonNull description: String, @NonNull 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

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

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

setCloseButtonIcon

@NonNull fun setCloseButtonIcon(@NonNull icon: Bitmap): CustomTabsIntent.Builder

Sets the Close button icon for the custom tab.

Parameters
icon Bitmap: The icon Bitmap

setColorScheme

@NonNull 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

@NonNull fun setColorSchemeParams(colorScheme: Int, @NonNull params: CustomTabColorSchemeParams): CustomTabsIntent.Builder

Sets CustomTabColorSchemeParams for the given color scheme. This can be useful if CustomTabsIntent#COLOR_SCHEME_SYSTEM is set: Custom Tabs will follow the system settings and apply the corresponding CustomTabColorSchemeParams "on the fly" when the settings change. For example, this allows specifying two different toolbar colors for light and dark schemes, whereas setToolbarColor will apply the given color to both schemes. 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 setToolbarColor and similar methods. If, on the other hand, a non-null value is present, it will override the default one. **Note**: to maintain compatibility with browsers not supporting this API, do provide the defaults. Example of setting two toolbar colors in backwards-compatible way:

<code>
              CustomTabColorSchemeParams darkParams = new CustomTabColorSchemeParams.Builder()
                      .setToolbarColor(darkColor)
                      .build();
              CustomTabIntent intent = new CustomTabIntent.Builder()
                      .setToolbarColor(lightColor)
                      .setColorScheme(COLOR_SCHEME_SYSTEM)
                      .setColorSchemeParams(COLOR_SCHEME_DARK, darkParams)
                      .build();
          </code>

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 Int: An instance of CustomTabColorSchemeParams.

setExitAnimations

@NonNull fun setExitAnimations(@NonNull context: Context, @AnimRes enterResId: Int, @AnimRes 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.

setInstantAppsEnabled

@NonNull 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

@NonNull fun setNavigationBarColor(color: 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 View#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 Int: The color for the navigation bar.

setSecondaryToolbarColor

@NonNull fun setSecondaryToolbarColor(color: Int): CustomTabsIntent.Builder

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

Parameters
color Int: The color for the secondary toolbar.

setSecondaryToolbarViews

@NonNull fun setSecondaryToolbarViews(@NonNull remoteViews: RemoteViews, @Nullable clickableIDs: IntArray?, @Nullable 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.

setSession

@NonNull fun setSession(@NonNull 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.

setShowTitle

@NonNull 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

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

@NonNull fun setToolbarColor(color: 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 View#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 Int: Color