CustomTabsIntent.Builder
public
static
final
class
CustomTabsIntent.Builder
extends Object
java.lang.Object | |
↳ | androidx.browser.customtabs.CustomTabsIntent.Builder |
Builder class for CustomTabsIntent
objects.
Summary
Public constructors | |
---|---|
Builder()
Creates a |
|
Builder(CustomTabsSession session)
Creates a |
Public methods | |
---|---|
CustomTabsIntent.Builder
|
addDefaultShareMenuItem()
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
addMenuItem(String label, PendingIntent pendingIntent)
Adds a menu item. |
CustomTabsIntent.Builder
|
addToolbarItem(int id, Bitmap icon, String description, PendingIntent pendingIntent)
This method 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
|
enableUrlBarHiding()
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
setActionButton(Bitmap icon, String description, PendingIntent pendingIntent, boolean shouldTint)
Sets the action button that is displayed in the Toolbar. |
CustomTabsIntent.Builder
|
setActionButton(Bitmap icon, String description, PendingIntent pendingIntent)
Sets the action button that is displayed in the Toolbar with default tinting behavior. |
CustomTabsIntent.Builder
|
setCloseButtonIcon(Bitmap icon)
Sets the Close button icon for the custom tab. |
CustomTabsIntent.Builder
|
setColorScheme(int colorScheme)
Sets the color scheme that should be applied to the user interface in the custom tab. |
CustomTabsIntent.Builder
|
setColorSchemeParams(int colorScheme, CustomTabColorSchemeParams params)
Sets |
CustomTabsIntent.Builder
|
setDefaultColorSchemeParams(CustomTabColorSchemeParams params)
Sets the default |
CustomTabsIntent.Builder
|
setDefaultShareMenuItemEnabled(boolean enabled)
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
setExitAnimations(Context context, int enterResId, int exitResId)
Sets the exit animations. |
CustomTabsIntent.Builder
|
setInstantAppsEnabled(boolean enabled)
Sets whether Instant Apps is enabled for this Custom Tab. |
CustomTabsIntent.Builder
|
setNavigationBarColor(int color)
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
setNavigationBarDividerColor(int color)
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
setSecondaryToolbarColor(int color)
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
setSecondaryToolbarViews(RemoteViews remoteViews, int[] clickableIDs, PendingIntent pendingIntent)
Sets the remote views displayed in the secondary toolbar in a custom tab. |
CustomTabsIntent.Builder
|
setSession(CustomTabsSession session)
Associates the |
CustomTabsIntent.Builder
|
setShareState(int shareState)
Sets the share state that should be applied to the custom tab. |
CustomTabsIntent.Builder
|
setShowTitle(boolean showTitle)
Sets whether the title should be shown in the custom tab. |
CustomTabsIntent.Builder
|
setStartAnimations(Context context, int enterResId, int exitResId)
Sets the start animations. |
CustomTabsIntent.Builder
|
setToolbarColor(int color)
This method is deprecated.
Use |
CustomTabsIntent.Builder
|
setUrlBarHidingEnabled(boolean enabled)
Set whether the url bar should hide as the user scrolls down on the page. |
Inherited methods | |
---|---|
Public constructors
Builder
public Builder ()
Creates a CustomTabsIntent.Builder
object associated with no
CustomTabsSession
.
Builder
public Builder (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 | |
---|---|
session |
CustomTabsSession : The session to associate this Builder with.
|
Public methods
addDefaultShareMenuItem
public CustomTabsIntent.Builder addDefaultShareMenuItem ()
This method is deprecated.
Use setShareState(int)
instead. This will set the share state to
CustomTabsIntent.SHARE_STATE_ON
.
Adds a default share item to the menu.
Returns | |
---|---|
CustomTabsIntent.Builder |
addMenuItem
public CustomTabsIntent.Builder addMenuItem (String label, PendingIntent pendingIntent)
Adds a menu item.
Parameters | |
---|---|
label |
String : Menu label. |
pendingIntent |
PendingIntent : Pending intent delivered when the menu item is clicked.
|
Returns | |
---|---|
CustomTabsIntent.Builder |
addToolbarItem
public CustomTabsIntent.Builder addToolbarItem (int id, Bitmap icon, String description, PendingIntent pendingIntent)
This method is 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 CustomTabsIntent.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 CustomTabsIntent.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 |
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. |
Returns | |
---|---|
CustomTabsIntent.Builder |
Throws | |
---|---|
IllegalStateException |
See also:
build
public CustomTabsIntent build ()
Combines all the options that have been set and returns a new CustomTabsIntent
object.
Returns | |
---|---|
CustomTabsIntent |
enableUrlBarHiding
public CustomTabsIntent.Builder enableUrlBarHiding ()
This method is deprecated.
Use setUrlBarHidingEnabled(boolean)
instead.
Enables the url bar to hide as the user scrolls down on the page.
Returns | |
---|---|
CustomTabsIntent.Builder |
setActionButton
public CustomTabsIntent.Builder setActionButton (Bitmap icon, String description, PendingIntent pendingIntent, boolean shouldTint)
Sets the action button that is displayed in the Toolbar.
This is equivalent to calling
addToolbarItem(int, Bitmap, String, PendingIntent)
with CustomTabsIntent.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.. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setActionButton
public CustomTabsIntent.Builder setActionButton (Bitmap icon, String description, PendingIntent pendingIntent)
Sets the action button that is displayed in the Toolbar with default tinting behavior.
Parameters | |
---|---|
icon |
Bitmap |
description |
String |
pendingIntent |
PendingIntent |
Returns | |
---|---|
CustomTabsIntent.Builder |
setCloseButtonIcon
public CustomTabsIntent.Builder setCloseButtonIcon (Bitmap icon)
Sets the Close button icon for the custom tab.
Parameters | |
---|---|
icon |
Bitmap : The icon Bitmap
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setColorScheme
public CustomTabsIntent.Builder setColorScheme (int colorScheme)
Sets the color scheme that should be applied to the user interface in the custom tab.
Parameters | |
---|---|
colorScheme |
int : Desired color scheme. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setColorSchemeParams
public CustomTabsIntent.Builder setColorSchemeParams (int colorScheme, 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 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.
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(CustomTabColorSchemeParams)
.
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(int) ).
It should not be CustomTabsIntent.COLOR_SCHEME_SYSTEM , because that represents
a behavior rather than a particular color scheme. |
params |
CustomTabColorSchemeParams : An instance of CustomTabColorSchemeParams .
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setDefaultColorSchemeParams
public CustomTabsIntent.Builder setDefaultColorSchemeParams (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(int, CustomTabColorSchemeParams)
.
Parameters | |
---|---|
params |
CustomTabColorSchemeParams : An instance of CustomTabColorSchemeParams .
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setDefaultShareMenuItemEnabled
public CustomTabsIntent.Builder setDefaultShareMenuItemEnabled (boolean enabled)
This method is deprecated.
Use setShareState(int)
instead. This will set the share state to
CustomTabsIntent.SHARE_STATE_ON
or CustomTabsIntent.SHARE_STATE_OFF
based on enabled
.
Set whether a default share item is added to the menu.
Parameters | |
---|---|
enabled |
boolean : Whether default share item is added. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setExitAnimations
public CustomTabsIntent.Builder setExitAnimations (Context context, int enterResId, int exitResId)
Sets the exit animations.
Parameters | |
---|---|
context |
Context : Application context. |
enterResId |
int : Resource ID of the "enter" animation for the application. |
exitResId |
int : Resource ID of the "exit" animation for the browser.
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setInstantAppsEnabled
public CustomTabsIntent.Builder setInstantAppsEnabled (boolean enabled)
Sets whether Instant Apps is enabled for this Custom Tab.
Parameters | |
---|---|
enabled |
boolean : Whether Instant Apps should be enabled.
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setNavigationBarColor
public CustomTabsIntent.Builder setNavigationBarColor (int color)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
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(int, CustomTabColorSchemeParams)
.
Parameters | |
---|---|
color |
int : The color for the navigation bar. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setNavigationBarDividerColor
public CustomTabsIntent.Builder setNavigationBarDividerColor (int color)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
Sets the navigation bar divider color. Has no effect on API versions below P.
Can be overridden for particular color schemes, see setColorSchemeParams(int, CustomTabColorSchemeParams)
.
Parameters | |
---|---|
color |
int : The color for the navigation bar divider. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setSecondaryToolbarColor
public CustomTabsIntent.Builder setSecondaryToolbarColor (int color)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
Sets the color of the secondary toolbar.
Can be overridden for particular color schemes, see setColorSchemeParams(int, CustomTabColorSchemeParams)
.
Parameters | |
---|---|
color |
int : The color for the secondary toolbar. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setSecondaryToolbarViews
public CustomTabsIntent.Builder setSecondaryToolbarViews (RemoteViews remoteViews, int[] clickableIDs, PendingIntent pendingIntent)
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 |
int : 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 View s in clickableIDs. When the
PendingIntent is sent, it will have the current URL as its
intent data. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setSession
public CustomTabsIntent.Builder setSession (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.
Parameters | |
---|---|
session |
CustomTabsSession |
Returns | |
---|---|
CustomTabsIntent.Builder |
setShareState
public CustomTabsIntent.Builder setShareState (int shareState)
Sets the share state that should be applied to the custom tab.
Parameters | |
---|---|
shareState |
int : Desired share state. |
Returns | |
---|---|
CustomTabsIntent.Builder |
setShowTitle
public CustomTabsIntent.Builder setShowTitle (boolean showTitle)
Sets whether the title should be shown in the custom tab.
Parameters | |
---|---|
showTitle |
boolean : Whether the title should be shown.
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setStartAnimations
public CustomTabsIntent.Builder setStartAnimations (Context context, int enterResId, int exitResId)
Sets the start animations.
Parameters | |
---|---|
context |
Context : Application context. |
enterResId |
int : Resource ID of the "enter" animation for the browser. |
exitResId |
int : Resource ID of the "exit" animation for the application.
|
Returns | |
---|---|
CustomTabsIntent.Builder |
setToolbarColor
public CustomTabsIntent.Builder setToolbarColor (int color)
This method is deprecated.
Use setDefaultColorSchemeParams(CustomTabColorSchemeParams)
instead.
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(int, CustomTabColorSchemeParams)
.
Parameters | |
---|---|
color |
int : Color |
Returns | |
---|---|
CustomTabsIntent.Builder |
setUrlBarHidingEnabled
public CustomTabsIntent.Builder setUrlBarHidingEnabled (boolean enabled)
Set whether the url bar should hide as the user scrolls down on the page.
Parameters | |
---|---|
enabled |
boolean : Whether url bar hiding is enabled.
|
Returns | |
---|---|
CustomTabsIntent.Builder |