Skip to content

AndroidBrowserOptionsBuilder

Fluent builder for AndroidBrowserOptions. Options not configured use the system or browser default.

Kodster.InAppWebBrowser.Android.AndroidBrowserOptionsBuilder

Overview

Each With* method returns the same builder instance for fluent chaining. Call Build() to create the final AndroidBrowserOptions object.

Each With* call is feature-gated against the detected androidx.browser version. If the feature is unsupported, the call is ignored and a warning is logged. See AndroidX Browser Version Requirements for the minimum version per feature.

Example

#if UNITY_ANDROID
var options = new AndroidBrowserOptionsBuilder()
    .WithColorScheme(AndroidColorScheme.Dark)
    .WithTitleShown(true)
    .WithUrlHidingEnabled(true)
    .Build();

AndroidBrowser.Open("https://example.com", options);
#endif

Methods

WithTitleShown

public AndroidBrowserOptionsBuilder WithTitleShown(
    bool titleShown
)

Sets whether the page title is shown in the toolbar.

Parameters

  • titleShown (bool): true to show the page title; otherwise false.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

WithShareButtonState

public AndroidBrowserOptionsBuilder WithShareButtonState(
    ShareButtonState shareButtonState
)

Sets the visibility of the share button.

Parameters

  • shareButtonState (ShareButtonState): The desired share button state.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.3.0 or higher.

WithUrlHidingEnabled

public AndroidBrowserOptionsBuilder WithUrlHidingEnabled(
    bool urlHidingEnabled
)

Sets whether the URL bar is hidden when scrolling down the page.

Parameters

  • urlHidingEnabled (bool): true to hide the URL bar.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.3.0 or higher.

WithBackgroundInteractionEnabled

public AndroidBrowserOptionsBuilder WithBackgroundInteractionEnabled(
    bool backgroundInteractionEnabled
)

Sets whether the user can interact with the app behind the browser while it is displayed in partial-screen mode.

Parameters

  • backgroundInteractionEnabled (bool): true to allow background interaction.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.7.0 or higher.

WithBookmarksButtonEnabled

public AndroidBrowserOptionsBuilder WithBookmarksButtonEnabled(
    bool bookmarksButtonEnabled
)

Sets whether the bookmark button is shown in the overflow menu.

Parameters

  • bookmarksButtonEnabled (bool): true to show the bookmarks button.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.7.0 or higher.

WithDownloadButtonEnabled

public AndroidBrowserOptionsBuilder WithDownloadButtonEnabled(
    bool downloadButtonEnabled
)

Sets whether the download button is shown in the overflow menu.

Parameters

  • downloadButtonEnabled (bool): true to show the download button.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.7.0 or higher.

WithEphemeralBrowsingEnabled

public AndroidBrowserOptionsBuilder WithEphemeralBrowsingEnabled(
    bool ephemeralBrowsingEnabled
)

Sets whether the browser clears cookies and browsing data when closed.

Parameters

  • ephemeralBrowsingEnabled (bool): true to enable ephemeral browsing.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.9.0 or higher.

WithColorScheme

public AndroidBrowserOptionsBuilder WithColorScheme(
    AndroidColorScheme androidColorScheme
)

Sets the color scheme used for the browser UI.

Parameters

  • androidColorScheme (AndroidColorScheme): The desired color scheme.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

WithLightColorSchemeOptions

public AndroidBrowserOptionsBuilder WithLightColorSchemeOptions(
    ColorSchemeOptions lightColorSchemeOptions
)

Sets the color customization applied when the browser is in light mode.

Parameters

  • lightColorSchemeOptions (ColorSchemeOptions): Light mode color options.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

WithDarkColorSchemeOptions

public AndroidBrowserOptionsBuilder WithDarkColorSchemeOptions(
    ColorSchemeOptions darkColorSchemeOptions
)

Sets the color customization applied when the browser is in dark mode.

Parameters

  • darkColorSchemeOptions (ColorSchemeOptions): Dark mode color options.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

WithDefaultColorSchemeOptions

public AndroidBrowserOptionsBuilder WithDefaultColorSchemeOptions(
    ColorSchemeOptions defaultColorSchemeOptions
)

Sets the fallback color customization used when no mode-specific options are matched.

Parameters

  • defaultColorSchemeOptions (ColorSchemeOptions): Fallback color options.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.3.0 or higher.

WithInitialHeightPercent

public AndroidBrowserOptionsBuilder WithInitialHeightPercent(
    int initialHeightPercent
)

Sets the initial height of the browser as a percentage of the screen height, in bottom-sheet mode. Clamped to 50–100.

Parameters

  • initialHeightPercent (int): Initial height as a percentage of the screen height.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.5.0 or higher.

WithInitialWidthPercent

public AndroidBrowserOptionsBuilder WithInitialWidthPercent(
    int initialWidthPercent
)

Sets the initial width of the browser as a percentage of the screen width, in side-sheet mode. Clamped to 33–100.

Parameters

  • initialWidthPercent (int): Initial width as a percentage of the screen width.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.8.0 or higher.

WithHeightResizeBehavior

public AndroidBrowserOptionsBuilder WithHeightResizeBehavior(
    HeightResizeBehavior heightResizeBehavior
)

Sets whether the user can resize the browser height in bottom-sheet mode.

Parameters

  • heightResizeBehavior (HeightResizeBehavior): The desired resize behavior.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.5.0 or higher.

WithToolbarCornerRadiusDp

public AndroidBrowserOptionsBuilder WithToolbarCornerRadiusDp(
    int toolbarCornerRadiusDp
)

Sets the corner radius of the toolbar, in density-independent pixels (dp). Clamped to 1–16.

Parameters

  • toolbarCornerRadiusDp (int): Corner radius in dp.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.5.0 or higher.

WithOpenTransition

public AndroidBrowserOptionsBuilder WithOpenTransition(
    AndroidBrowserTransition openAndroidBrowserTransition
)

Sets the transition played when the browser opens.

Parameters

  • openAndroidBrowserTransition (AndroidBrowserTransition): Transition to play on open.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

WithCloseTransition

public AndroidBrowserOptionsBuilder WithCloseTransition(
    AndroidBrowserTransition closeAndroidBrowserTransition
)

Sets the transition played when the browser closes.

Parameters

  • closeAndroidBrowserTransition (AndroidBrowserTransition): Transition to play on close.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

WithAppSpecificHistoryEnabled

public AndroidBrowserOptionsBuilder WithAppSpecificHistoryEnabled(
    bool appSpecificHistoryEnabled
)

Sets whether to opt in to App-specific history, available from Chrome 126 on Android 14+. When enabled, links opened in the browser are recorded in Chrome's history alongside the app's name, allowing users to find and resume previously visited pages.

Parameters

  • appSpecificHistoryEnabled (bool): true to enable app-specific history.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.7.0 or higher.

WithOpenInExternalHandlerEnabled

public AndroidBrowserOptionsBuilder WithOpenInExternalHandlerEnabled(
    bool openInExternalHandlerEnabled
)

Sets whether URLs that match an external app's default handler are forwarded to that app instead of being opened inside the browser.

Parameters

  • openInExternalHandlerEnabled (bool): true to route matching URLs to external apps.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.7.0 or higher.

WithSideSheetBreakpointDp

public AndroidBrowserOptionsBuilder WithSideSheetBreakpointDp(
    int sideSheetBreakpointDp
)

Sets the screen width, in dp, at which the browser switches to side-sheet mode.

Parameters

  • sideSheetBreakpointDp (int): Breakpoint width in dp.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.8.0 or higher.

WithSideSheetDecoration

public AndroidBrowserOptionsBuilder WithSideSheetDecoration(
    SideSheetDecoration sideSheetDecoration
)

Sets the decoration style applied to the side-sheet.

Parameters

  • sideSheetDecoration (SideSheetDecoration): The desired decoration style.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.8.0 or higher.

WithSideSheetMaximizationEnabled

public AndroidBrowserOptionsBuilder WithSideSheetMaximizationEnabled(
    bool sideSheetMaximizationEnabled
)

Sets whether the side-sheet can be maximized to fill the screen.

Parameters

  • sideSheetMaximizationEnabled (bool): true to allow maximization.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.8.0 or higher.

WithSideSheetPosition

public AndroidBrowserOptionsBuilder WithSideSheetPosition(
    SideSheetPosition sideSheetPosition
)

Sets the position of the side-sheet on the screen.

Parameters

  • sideSheetPosition (SideSheetPosition): The desired side-sheet position.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.8.0 or higher.

WithSideSheetRoundedCornersPosition

public AndroidBrowserOptionsBuilder WithSideSheetRoundedCornersPosition(
    SideSheetRoundedCornersPosition sheetRoundedCornersPosition
)

Sets which corners of the side-sheet have rounded styling applied.

Parameters

  • sheetRoundedCornersPosition (SideSheetRoundedCornersPosition): Rounded corner position rule.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.8.0 or higher.

WithCloseButtonPosition

public AndroidBrowserOptionsBuilder WithCloseButtonPosition(
    CloseButtonPosition closeButtonPosition
)

Sets the position of the close button in the toolbar.

Parameters

  • closeButtonPosition (CloseButtonPosition): The desired close button position.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.5.0 or higher.

WithCloseButtonIcon

public AndroidBrowserOptionsBuilder WithCloseButtonIcon(
    CloseButtonIcon closeButtonIcon
)

Sets the icon style used for the close button.

Parameters

  • closeButtonIcon (CloseButtonIcon): The desired close button icon.

Returns

  • The current AndroidBrowserOptionsBuilder instance.

Remarks

  • Requires androidx.browser version 1.2.0 or higher.

Build

public AndroidBrowserOptions Build()

Builds and returns an AndroidBrowserOptions instance from the current configuration. Only options explicitly set via the With* methods are included; unset options remain null.

Returns

  • A new AndroidBrowserOptions instance reflecting the builder's current state.