UniWebViewEmbeddedToolbar
Summary
Represents the embedded toolbar in a web view.
You do not create an instance of this class directly. Instead, use the EmbeddedToolbar property in UniWebView to get the current embedded toolbar in the web view and interact with it.
The embedded toolbar of a web view expands its width to match the web view's frame width. It is displayed at either top or bottom of the web view, based on the setting received through SetPosition. By default, the toolbar contains a main title, a back button, a forward button and a done button to close the web view.
You can customize the toolbar through the config-based approach: create a UniWebViewEmbeddedToolbarConfig, set up items (built-in or custom), colors, title interactions, and apply it via ApplyConfig. This gives you full control over the toolbar layout, including adding custom buttons, a reload button, and title interactions like scroll-to-top or copy-URL-on-long-press.
For simple customization, convenience methods like SetDoneButtonText, SetBackgroundColor, etc. are also available. These methods modify the current config internally and apply the changes automatically.
Properties Summary
Gets a cloned copy of the current toolbar config. |
Methods Summary
Applies a toolbar config to fully customize the toolbar layout and behavior. | |
Sets the position of the embedded toolbar. | |
Sets the maximum height of the toolbar. | |
Shows the toolbar. | |
Hides the toolbar. | |
Sets the text of the done button. | |
Sets the text of the back button. | |
Sets the text of the forward button. | |
Sets the text of toolbar title. | |
Sets the background color of the toolbar. | |
Sets the buttons color of the toolbar. | |
Sets the text color of the toolbar title. | |
Hides the navigation buttons on the toolbar. | |
Shows the navigation buttons on the toolbar. |
Properties
Gets a cloned copy of the current toolbar config.
You can use this to inspect the current state of the toolbar, or as a starting point for building a modified config. Changes to the returned object will not affect the toolbar until you pass it to ApplyConfig.
Example
// Get the current config as a starting point for modifications.
var config = webView.EmbeddedToolbar.CurrentConfig;
config.BackgroundColor = UniWebViewEmbeddedToolbarConfig.ColorValue.FromColor(Color.black);
webView.EmbeddedToolbar.ApplyConfig(config);
Methods
Applies a toolbar config to fully customize the toolbar layout and behavior.
This is the recommended way to configure the toolbar. You can control which items appear (back, forward, done, reload, title, or custom buttons), their order and placement (left, center, right sections), colors, and title interactions (tap to scroll to top, long press to copy URL).
After calling this method, the toolbar will be re-rendered with the given config. Pass null to reset to the default config.
- UniWebViewEmbeddedToolbarConfig config
The toolbar config to apply. Pass
nullto apply the default config.
Example
var config = UniWebViewEmbeddedToolbarConfig.Default;
// Add a reload button to the left section.
config.Left.Add(
UniWebViewEmbeddedToolbarConfig.Item.BuiltIn(
UniWebViewEmbeddedToolbarConfig.BuiltInItemKind.Reload
)
);
// Set the title text and enable title interactions.
var titleItem = config.FindFirstBuiltInItem(
UniWebViewEmbeddedToolbarConfig.BuiltInItemKind.Title
);
titleItem.Title = "My App";
titleItem.TitleInteraction = new UniWebViewEmbeddedToolbarConfig.TitleInteraction {
OnTap = UniWebViewEmbeddedToolbarConfig.TitleInteraction.TapAction.ScrollToTop,
OnLongPress = UniWebViewEmbeddedToolbarConfig.TitleInteraction.LongPressAction.CopyUrl
};
webView.EmbeddedToolbar.ApplyConfig(config);
Sets the position of the embedded toolbar. You can put the toolbar at either top or bottom of your web view.
The default position is Top.
- UniWebViewToolbarPosition position
The desired position of the toolbar.
Example
// Sets the web view shows the toolbar at the bottom.
webView.EmbeddedToolbar.SetPosition(UniWebViewToolbarPosition.Bottom);
webView.EmbeddedToolbar.Show();
Sets the maximum height of the toolbar. If the specified height is smaller than the toolbar's standard height, the toolbar will be resized to this height. Otherwise, the standard height will be used.
This method only works on iOS and Android. On macOS Unity Editor, the toolbar will always be displayed in the window's title bar and the height is fixed.
- float height
The maximum height value.
Shows the toolbar.
Example
webView.EmbeddedToolbar.Show();
Hides the toolbar.
Example
webView.EmbeddedToolbar.Hide();
Sets the text of the done button.
The default text is "Done".
- string text
The desired text to display as the done button.
Example
webView.EmbeddedToolbar.SetDoneButtonText("Close");
Sets the text of the back button.
The default text is "❮" ("❮").
- string text
The desired text to display as the back button.
Example
webView.EmbeddedToolbar.SetGoBackButtonText("Back");
Sets the text of the forward button.
The default text is "❯" ("❯").
- string text
The desired text to display as the forward button.
Example
webView.EmbeddedToolbar.SetGoForwardButtonText("Fwd");
Sets the text of toolbar title.
The default is empty. The space is limited, setting a long text as title might not fit in the space.
- string text
The desired text to display as the title in the toolbar.
Example
webView.EmbeddedToolbar.SetTitleText("My Game");
Sets the background color of the toolbar.
- Color color
The desired color of toolbar's background.
Example
webView.EmbeddedToolbar.SetBackgroundColor(Color.yellow);
Sets the buttons color of the toolbar.
This color affects the back, forward and done button.
- Color color
The desired color of toolbar's buttons.
Example
webView.EmbeddedToolbar.SetButtonTextColor(Color.red);
Sets the text color of the toolbar title.
- Color color
The desired color of the toolbar's title.
Example
webView.EmbeddedToolbar.SetTitleTextColor(Color.blue);
Hides the navigation buttons on the toolbar.
When called, the back button and forward button will not be shown. By default, the navigation buttons are shown.
Example
// Do not show the navigation buttons (go back and go forward).
webView.EmbeddedToolbar.HideNavigationButtons();
Shows the navigation buttons on the toolbar.
When called, the back button and forward button will be shown. By default, the navigation buttons are shown.
