Toolbar
open class Toolbar : ViewGroup
kotlin.Any | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | androidx.appcompat.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
LayoutParams
indicates aGravity
value ofCENTER_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.
androidx.appcompat.R.attr#buttonGravity
androidx.appcompat.R.attr#collapseContentDescription
androidx.appcompat.R.attr#collapseIcon
androidx.appcompat.R.attr#contentInsetEnd
androidx.appcompat.R.attr#contentInsetLeft
androidx.appcompat.R.attr#contentInsetRight
androidx.appcompat.R.attr#contentInsetStart
androidx.appcompat.R.attr#contentInsetStartWithNavigation
androidx.appcompat.R.attr#contentInsetEndWithActions
android.R.attr#gravity
androidx.appcompat.R.attr#logo
androidx.appcompat.R.attr#logoDescription
androidx.appcompat.R.attr#maxButtonHeight
androidx.appcompat.R.attr#navigationContentDescription
androidx.appcompat.R.attr#navigationIcon
androidx.appcompat.R.attr#popupTheme
androidx.appcompat.R.attr#subtitle
androidx.appcompat.R.attr#subtitleTextAppearance
androidx.appcompat.R.attr#subtitleTextColor
androidx.appcompat.R.attr#title
androidx.appcompat.R.attr#titleMargin
androidx.appcompat.R.attr#titleMarginBottom
androidx.appcompat.R.attr#titleMarginEnd
androidx.appcompat.R.attr#titleMarginStart
androidx.appcompat.R.attr#titleMarginTop
androidx.appcompat.R.attr#titleTextAppearance
androidx.appcompat.R.attr#titleTextColor
androidx.appcompat.R.attr#menu
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. |
open |
Public constructors | |
---|---|
<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?) |
|
<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: 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! |
generateLayoutParams(attrs: AttributeSet!) |
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! |
getLogo() Return the current logo drawable. |
open CharSequence! |
Return the description of the toolbar's logo. |
open Menu! |
getMenu() 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! |
getTitle() 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(@MenuRes resId: Int) Inflate a menu resource into this toolbar. |
open Boolean |
Check whether the overflow menu is currently showing. |
open Boolean |
onHoverEvent(ev: MotionEvent!) |
open Unit |
onRtlPropertiesChanged(layoutDirection: Int) |
open Boolean |
onTouchEvent(ev: MotionEvent!) |
open Unit |
setCollapseContentDescription(@StringRes resId: Int) Set a content description for the collapse button if one is present. |
open Unit |
setCollapseContentDescription(@Nullable description: CharSequence?) Set a content description for the collapse button if one is present. |
open Unit |
setCollapseIcon(@DrawableRes resId: Int) Set the icon to use for the toolbar's collapse button. |
open Unit |
setCollapseIcon(@Nullable icon: Drawable?) 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 |
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 |
Set a logo drawable from a resource id. |
open Unit |
Set a logo drawable. |
open Unit |
setLogoDescription(@StringRes resId: Int) Set a description of the toolbar's logo. |
open Unit |
setLogoDescription(description: CharSequence!) Set a description of the toolbar's logo. |
open Unit |
setNavigationContentDescription(@StringRes : Int) Set a content description for the navigation button if one is present. |
open Unit |
setNavigationContentDescription(@Nullable : CharSequence?) Set a content description for the navigation button if one is present. |
open Unit |
setNavigationIcon(@DrawableRes : Int< |