Added in API level 21

Toolbar


open class Toolbar : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.Toolbar

A standard toolbar for use within application content.

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setActionBar() method.

Toolbar supports a more focused feature set than ActionBar. From start to end, a toolbar may contain a combination of the following optional elements:

  • A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.
  • A branded logo image. This may extend to the height of the bar and can be arbitrarily wide.
  • A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
  • One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout. If a child view's LayoutParams indicates a Gravity value of CENTER_HORIZONTAL the view will attempt to center within the available space remaining in the Toolbar after all other elements have been measured.
  • An action menu. The menu of actions will pin to the end of the Toolbar offering a few frequent, important or typical actions along with an optional overflow menu for additional actions. Action buttons are vertically aligned within the Toolbar's minimum height, if set.

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

Summary

Nested classes
open

Layout information for child views of Toolbars.

abstract

Interface responsible for receiving menu item click events if the items themselves do not have individual item click listeners.

XML attributes
android:buttonGravity
android:collapseContentDescription Text to set as the content description for the collapse button.
android:collapseIcon Icon drawable to use for the collapse button.
android:contentInsetEnd Minimum inset for content views within a bar.
android:contentInsetEndWithActions Minimum inset for content views within a bar when actions from a menu are present.
android:contentInsetLeft Minimum inset for content views within a bar.
android:contentInsetRight Minimum inset for content views within a bar.
android:contentInsetStart Minimum inset for content views within a bar.
android:contentInsetStartWithNavigation Minimum inset for content views within a bar when a navigation button is present, such as the Up button.
android:gravity Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
android:logo Drawable to set as the logo that appears at the starting side of the Toolbar, just after the navigation button.
android:logoDescription A content description string to describe the appearance of the associated logo image.
android:maxButtonHeight
android:navigationContentDescription Text to set as the content description for the navigation button located at the start of the toolbar.
android:navigationIcon Icon drawable to use for the navigation button located at the start of the toolbar.
android:popupTheme Reference to a theme that should be used to inflate popups shown by widgets in the toolbar.
android:subtitle Specifies subtitle text used for navigationMode="normal".
android:subtitleTextAppearance
android:subtitleTextColor A color to apply to the subtitle string.
android:title The title associated with the item.
android:titleMargin Specifies extra space on the left, start, right and end sides of the toolbar's title.
android:titleMarginBottom Specifies extra space on the bottom side of the toolbar's title.
android:titleMarginEnd Specifies extra space on the end side of the toolbar's title.
android:titleMarginStart Specifies extra space on the start side of the toolbar's title.
android:titleMarginTop Specifies extra space on the top side of the toolbar's title.
android:titleTextAppearance
android:titleTextColor A color to apply to the title string.
Inherited XML attributes
Inherited constants
Public constructors
Toolbar(context: Context!)

Toolbar(context: Context!, attrs: AttributeSet!)

Toolbar(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Toolbar(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

Collapse a currently expanded action view.

open Unit

Dismiss all currently showing popup menus, including overflow or submenus.

open Toolbar.LayoutParams!

open CharSequence?

Retrieve the currently configured content description for the collapse button view.

open Drawable?

Return the current drawable used as the collapse icon.

open Int

Gets the ending content inset for this toolbar.

open Int

Gets the end content inset to use when action buttons are present.

open Int

Gets the left content inset for this toolbar.

open Int

Gets the right content inset for this toolbar.

open Int

Gets the starting content inset for this toolbar.

open Int

Gets the start content inset to use when a navigation button is present.

open Int

Gets the content inset that will be used on the ending side of the bar in the current toolbar configuration.

open Int

Gets the content inset that will be used on the left side of the bar in the current toolbar configuration.

open Int

Gets the content inset that will be used on the right side of the bar in the current toolbar configuration.

open Int

Gets the content inset that will be used on the starting side of the bar in the current toolbar configuration.

open Drawable!

Return the current logo drawable.

open CharSequence!

Return the description of the toolbar's logo.

open Menu!

Return the Menu shown in the toolbar.

open CharSequence?

Retrieve the currently configured content description for the navigation button view.

open Drawable?

Return the current drawable used as the navigation icon.

open Drawable?

Return the current drawable used as the overflow icon.

open Int

open CharSequence!

Return the subtitle of this toolbar.

open CharSequence!

Returns the title of this toolbar.

open Int

open Int

open Int

open Int

open Boolean

Check whether this Toolbar is currently hosting an expanded action view.

open Boolean

Hide the overflow items from the associated menu.

open Unit
inflateMenu(resId: Int)

Inflate a menu resource into this toolbar.

open Boolean

Check whether the overflow menu is currently showing.

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

Called when any RTL property (layout direction or text direction or text alignment) has been changed.

open Boolean

open Unit

Set a content description for the collapse button if one is present.

open Unit

Set a content description for the collapse button if one is present.

open Unit

Set the icon to use for the toolbar's collapse button.

open Unit

Set the icon to use for the toolbar's collapse button.

open Unit
setContentInsetEndWithActions(insetEndWithActions: Int)

Sets the start content inset to use when action buttons are present.

open Unit
setContentInsetStartWithNavigation(insetStartWithNavigation: Int)

Sets the start content inset to use when a navigation button is present.

open Unit
setContentInsetsAbsolute(contentInsetLeft: Int, contentInsetRight: Int)

Sets the content insets for this toolbar.

open Unit
setContentInsetsRelative(contentInsetStart: Int, contentInsetEnd: Int)

Sets the content insets for this toolbar relative to layout direction.

open Unit
setLogo(drawable: Drawable!)

Set a logo drawable.

open Unit
setLogo(resId: Int)

Set a logo drawable from a resource id.

open Unit

Set a description of the toolbar's logo.

open Unit

Set a description of the toolbar's logo.

open Unit

Set a content description for the navigation button if one is present.

open Unit

Set a content description for the navigation button if one is present.

open Unit

Set the icon to use for the toolbar's navigation button.

open Unit

Set the icon to use for the toolbar's navigation button.

open Unit

Set a listener to respond to navigation events.

open Unit

Set a listener to respond to menu item click events.

open Unit

Set the icon to use for the overflow button.

open Unit

Specifies the theme to use when inflating popup menus.

open Unit
setSubtitle(resId: Int)

Set the subtitle of this toolbar.

open Unit

Set the subtitle of this toolbar.

open Unit

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

open Unit

Sets the text color of the subtitle, if present.

open Unit
setTitle(resId: Int)

Set the title of this toolbar.

open Unit

Set the title of this toolbar.

open Unit
setTitleMargin(start: Int, top: Int, end: Int, bottom: Int)

Sets the title margin.

open Unit

Sets the bottom title margin in pixels.

open Unit

Sets the ending title margin in pixels.

open Unit

Sets the starting title margin in pixels.

open Unit

Sets the top title margin in pixels.

open Unit
setTitleTextAppearance(context: Context!, resId: Int)

Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.

open Unit

Sets the text color of the title, if present.

open Boolean

Show the overflow items from the associated menu.

Protected methods
open Boolean

open Toolbar.LayoutParams!

open Toolbar.LayoutParams!

open Unit

open Unit

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Unit

open Parcelable?

Inherited functions