android-components / mozilla.components.browser.toolbar / BrowserToolbar

# BrowserToolbar

`class BrowserToolbar : ViewGroup, Toolbar` (source)

A customizable toolbar for browsers.

The toolbar can switch between two modes: display and edit. The display mode displays the current URL and controls for navigation. In edit mode the current URL can be edited. Those two modes are implemented by the DisplayToolbar and EditToolbar classes.

        +----------------+
        | BrowserToolbar |
        +--------+-------+
                 +
         +-------+-------+
         |               |

+---------v------+ +-------v--------+ | DisplayToolbar | | EditToolbar | +----------------+ +----------------+

### Types

Button | `class Button : ActionButton` An action button to be added to the toolbar.
ToggleButton | `class ToggleButton : ActionToggleButton` An action button with two states, selected and unselected. When the button is pressed, the state changes automatically.
TwoStateButton | `class TwoStateButton : Button` An action that either shows an active button or an inactive button based on the provided isEnabled lambda.

### Constructors

<init> | `BrowserToolbar(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)` A customizable toolbar for browsers.

### Properties

browserActionMargin | `var browserActionMargin: Int` Gets/Sets the margin to be used between browser actions.
displaySiteSecurityIcon | `var displaySiteSecurityIcon: Boolean` Set/Get whether a site security icon (usually a lock or globe icon) should be next to the URL.
hint | `var hint: String` Sets the text to be displayed when the URL of the toolbar is empty.
hintColor | `var hintColor: Int` Sets the colour of the text to be displayed when the URL of the toolbar is empty.
onUrlClicked | `var onUrlClicked: () -> Boolean` Sets a lambda that will be invoked whenever the URL in display mode was clicked. Only if this lambda returns true the toolbar will switch to editing mode. Return false to not switch to editing mode and handle the click manually.
siteSecure | `var siteSecure: SiteSecurity` Sets/Gets the site security to be displayed on the toolbar.
textColor | `var textColor: Int` Sets the colour of the text for the URL/search term displayed in the toolbar.
textSize | `var textSize: Float` Sets the size of the text for the URL/search term displayed in the toolbar.
typeface | `var typeface: Typeface` Sets the typeface of the text for the URL/search term displayed in the toolbar.
url | `var url: String` Sets/Gets the URL to be displayed on the toolbar.
urlBoxMargin | `var urlBoxMargin: Int` Gets/Sets horizontal margin of the URL box (surrounding URL and page actions) in display mode.
urlBoxView | `var urlBoxView: View?` Gets/Sets a custom view that will be drawn as behind the URL and page actions in display mode.

### Functions

addBrowserAction | `fun addBrowserAction(action: Action): Unit` Adds an action to be displayed on the right side of the toolbar (outside of the URL bounding box) in display mode.
addNavigationAction | `fun addNavigationAction(action: Action): Unit` Adds an action to be display on the far left side of the toolbar. This area is usually used on larger devices for navigation actions like "back" and "forward".
addPageAction | `fun addPageAction(action: Action): Unit` Adds an action to be displayed on the right side of the URL in display mode.
displayMode | `fun displayMode(): Unit` Switches to URL displaying mode.
displayProgress | `fun displayProgress(progress: Int): Unit` Displays the given loading progress. Expects values in the range 0,100.
editMode | `fun editMode(): Unit` Switches to URL editing mode.
invalidateActions | `fun invalidateActions(): Unit` Declare that the actions (navigation actions, browser actions, page actions) have changed and should be updated if needed.
onBackPressed | `fun onBackPressed(): Boolean` Should be called by an activity when the user pressed the back key of the device.
onLayout | `fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int): Unit`
onMeasure | `fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit`
setAutocompleteListener | `fun setAutocompleteListener(filter: (String, AutocompleteDelegate) -> Unit): Unit` Registers the given function to be invoked when users changes text in the toolbar.
setMenuBuilder | `fun setMenuBuilder(menuBuilder: BrowserMenuBuilder): Unit` Sets a BrowserMenuBuilder that will be used to create a menu when the menu button is clicked. The menu button will only be visible if a builder has been set.
setOnEditFocusChangeListener | `fun setOnEditFocusChangeListener(listener: (Boolean) -> Unit): Unit` Sets a listener to be invoked when focus of the URL input view (in edit mode) changed.
setOnEditListener | `fun setOnEditListener(listener: OnEditListener): Unit` Registers the given listener to be invoked when the user edits the URL.
setOnUrlCommitListener | `fun setOnUrlCommitListener(listener: (String) -> Unit): Unit` Registers the given function to be invoked when the user selected a new URL i.e. is done editing.
setSearchTerms | `fun setSearchTerms(searchTerms: String): Unit` Displays the currently used search terms as part of this Toolbar.
setUrlTextPadding | `fun setUrlTextPadding(left: Int = displayToolbar.urlView.paddingLeft, top: Int = displayToolbar.urlView.paddingTop, right: Int = displayToolbar.urlView.paddingRight, bottom: Int = displayToolbar.urlView.paddingBottom): Unit` Sets the padding to be applied to the URL text (in display mode).

### Inherited Functions

asView | `open fun asView(): View` Casts this toolbar to an Android View object.

### Extension Properties

isLTR | `val View.isLTR: Boolean` Is the horizontal layout direction of this view from Left to Right?
isRTL | `val View.isRTL: Boolean` Is the horizontal layout direction of this view from Right to Left?

### Extension Functions

forEach | `fun ViewGroup.forEach(action: (View) -> Unit): Unit` Performs the given action on each View in this ViewGroup.
hideKeyboard | `fun View.hideKeyboard(): Unit` Hides the soft input window.
isGone | `fun View.isGone(): Boolean` Returns true if this view's visibility is set to View.GONE.
isInvisible | `fun View.isInvisible(): Boolean` Returns true if this view's visibility is set to View.INVISIBLE.
isVisible | `fun View.isVisible(): Boolean` Returns true if this view's visibility is set to View.VISIBLE.
setPadding | `fun View.setPadding(padding: Padding): Unit` Set a padding using Padding object.
showKeyboard | `fun View.showKeyboard(flags: Int = InputMethodManager.SHOW_IMPLICIT): Unit` Tries to focus this view and show the soft input window for it.