Stay organized with collections Save and categorize content based on your preferences.
added in version 25.1.0
belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1

Toolbar

public class Toolbar
extends ViewGroup

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v7.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 setSupportActionBar() 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 Toolbar.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

class Toolbar.LayoutParams

Layout information for child views of Toolbars. 

interface Toolbar.OnMenuItemClickListener

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

class Toolbar.SavedState

 

XML attributes

Toolbar_android_gravity  
Toolbar_buttonGravity  
Toolbar_collapseContentDescription  
Toolbar_collapseIcon  
Toolbar_contentInsetEnd  
Toolbar_contentInsetEndWithActions  
Toolbar_contentInsetLeft  
Toolbar_contentInsetRight  
Toolbar_contentInsetStart  
Toolbar_contentInsetStartWithNavigation  
Toolbar_logo  
Toolbar_logoDescription  
Toolbar_maxButtonHeight  
Toolbar_navigationContentDescription  
Toolbar_navigationIcon  
Toolbar_popupTheme  
Toolbar_subtitle  
Toolbar_subtitleTextAppearance  
Toolbar_subtitleTextColor  
Toolbar_title  
Toolbar_titleMargin  
Toolbar_titleMarginBottom  
Toolbar_titleMarginEnd  
Toolbar_titleMarginStart  
Toolbar_titleMarginTop  
Toolbar_titleTextAppearance  
Toolbar_titleTextColor  

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

Toolbar(Context context)
Toolbar(Context context, AttributeSet attrs)
Toolbar(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

void collapseActionView()

Collapse a currently expanded action view.

void dismissPopupMenus()

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

Toolbar.LayoutParams generateLayoutParams(AttributeSet attrs)
int getContentInsetEnd()

Gets the ending content inset for this toolbar.

int getContentInsetEndWithActions()

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

int getContentInsetLeft()

Gets the left content inset for this toolbar.

int getContentInsetRight()

Gets the right content inset for this toolbar.

int getContentInsetStart()

Gets the starting content inset for this toolbar.

int getContentInsetStartWithNavigation()

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

int getCurrentContentInsetEnd()

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

int getCurrentContentInsetLeft()

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

int getCurrentContentInsetRight()

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

int getCurrentContentInsetStart()

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

Drawable getLogo()

Return the current logo drawable.

CharSequence getLogoDescription()

Return the description of the toolbar's logo.