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 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.
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. |
Menu
|
getMenu()
Return the Menu shown in the toolbar. |
CharSequence
|
getNavigationContentDescription()
Retrieve the currently configured content description for the navigation button view. |
Drawable
|
getNavigationIcon()
Return the current drawable used as the navigation icon. |
Drawable
|
getOverflowIcon()
Return the current drawable used as the overflow icon. |
int
|
getPopupTheme()
|
CharSequence
|
getSubtitle()
Return the subtitle of this toolbar. |
CharSequence
|
getTitle()
Returns the title of this toolbar. |
int
|
getTitleMarginBottom()
|
int
|
getTitleMarginEnd()
|
int
|
getTitleMarginStart()
|
int
|
getTitleMarginTop()
|
boolean
|
hasExpandedActionView()
Check whether this Toolbar is currently hosting an expanded action view. |
boolean
|
hideOverflowMenu()
Hide the overflow items from the associated menu. |
void
|
inflateMenu(int resId)
Inflate a menu resource into this toolbar. |
boolean
|
isOverflowMenuShowing()
Check whether the overflow menu is currently showing. |
boolean
|
onHoverEvent(MotionEvent ev)
|
void
|
onRtlPropertiesChanged(int layoutDirection)
|
boolean
|
onTouchEvent(MotionEvent ev)
|
void
|
setContentInsetEndWithActions(int insetEndWithActions)
Sets the start content inset to use when action buttons are present. |
void
|
setContentInsetStartWithNavigation(int insetStartWithNavigation)
Sets the start content inset to use when a navigation button is present. |
void
|
setContentInsetsAbsolute(int contentInsetLeft, int contentInsetRight)
Sets the content insets for this toolbar. |
void
|
setContentInsetsRelative(int contentInsetStart, int contentInsetEnd)
Sets the content insets for this toolbar relative to layout direction. |
void
|
setLogo(int resId)
Set a logo drawable from a resource id. |
void
|
setLogo(Drawable drawable)
Set a logo drawable. |
void
|
setLogoDescription(int resId)
Set a description of the toolbar's logo. |
void
|
setLogoDescription(CharSequence description)
Set a description of the toolbar's logo. |
void
|
setNavigationContentDescription(CharSequence description)
Set a content description for the navigation button if one is present. |
void
|
setNavigationContentDescription(int resId)
Set a content description for the navigation button if one is present. |
void
|
setNavigationIcon(Drawable icon)
Set the icon to use for the toolbar's navigation button. |
void
|
setNavigationIcon(int resId)
Set the icon to use for the toolbar's navigation button. |
void
|
setNavigationOnClickListener(View.OnClickListener listener)
Set a listener to respond to navigation events. |
void
|
setOnMenuItemClickListener(Toolbar.OnMenuItemClickListener listener)
Set a listener to respond to menu item click events. |
void
|
setOverflowIcon(Drawable icon)
Set the icon to use for the overflow button. |
void
|
setPopupTheme(int resId)
Specifies the theme to use when inflating popup menus. |
void
|
setSubtitle(CharSequence subtitle)
Set the subtitle of this toolbar. |
void
|
setSubtitle(int resId)
Set the subtitle of this toolbar. |
void
|
setSubtitleTextAppearance(Context context, int resId)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource. |
void
|
setSubtitleTextColor(int color)
Sets the text color of the subtitle, if present. |
void
|
setTitle(CharSequence title)
Set the title of this toolbar. |
void
|
setTitle(int resId)
Set the title of this toolbar. |
void
|
setTitleMargin(int start, int top, int end, int bottom)
Sets the title margin. |
void
|
setTitleMarginBottom(int margin)
Sets the bottom title margin in pixels. |
void
|
setTitleMarginEnd(int margin)
Sets the ending title margin in pixels. |
void
|
setTitleMarginStart(int margin)
Sets the starting title margin in pixels. |
void
|
setTitleMarginTop(int margin)
Sets the top title margin in pixels. |
void
|
setTitleTextAppearance(Context context, int resId)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource. |
void
|
setTitleTextColor(int color)
Sets the text color of the title, if present. |
boolean
|
showOverflowMenu()
Show the overflow items from the associated menu. |
Protected methods | |
---|---|
boolean
|
checkLayoutParams(ViewGroup.LayoutParams p)
|
Toolbar.LayoutParams
|
generateDefaultLayoutParams()
|
Toolbar.LayoutParams
|
generateLayoutParams(ViewGroup.LayoutParams p)
|
void
|
onDetachedFromWindow()
|
void
|
onLayout(boolean changed, int l, int t, int r, int b)
|
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
void
|
onRestoreInstanceState(Parcelable state)
|
Parcelable
|
onSaveInstanceState()
|
Inherited methods | |
---|---|
From
class
android.view.ViewGroup
| |
From
class
android.view.View
| |
From
class
java.lang.Object
| |
From
interface
android.view.ViewParent
| |
From
interface
android.view.ViewManager
| |
From
interface
android.graphics.drawable.Drawable.Callback
| |
From
interface
android.view.KeyEvent.Callback
| |
From
interface
android.view.accessibility.AccessibilityEventSource
|
XML attributes
Toolbar_android_gravity
Toolbar_buttonGravity
Toolbar_collapseContentDescription
Toolbar_collapseIcon
Toolbar_contentInsetEnd
Related methods:
Toolbar_contentInsetEndWithActions
Related methods:
Toolbar_contentInsetLeft
Related methods:
Toolbar_contentInsetRight
Related methods:
Toolbar_contentInsetStart
Related methods:
Toolbar_contentInsetStartWithNavigation
Related methods:
Toolbar_logo
Toolbar_logoDescription
Toolbar_maxButtonHeight
Toolbar_navigationContentDescription
Related methods:
Toolbar_navigationIcon
Related methods:
Toolbar_popupTheme
Toolbar_subtitle
Toolbar_subtitleTextAppearance
Toolbar_subtitleTextColor
Toolbar_title
Toolbar_titleMargin
Related methods:
Toolbar_titleMarginBottom
Related methods:
Toolbar_titleMarginEnd
Related methods:
Toolbar_titleMarginStart
Related methods:
Toolbar_titleMarginTop
Related methods:
Toolbar_titleTextAppearance
Toolbar_titleTextColor
Public constructors
Toolbar
Toolbar (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
Toolbar
Toolbar (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
Public methods
collapseActionView
void collapseActionView ()
Collapse a currently expanded action view. If this Toolbar does not have an expanded action view this method has no effect.
An action view may be expanded either directly from the
MenuItem
it belongs to or by user action.
See also:
dismissPopupMenus
void dismissPopupMenus ()
Dismiss all currently showing popup menus, including overflow or submenus.
generateLayoutParams
Toolbar.LayoutParams generateLayoutParams (AttributeSet attrs)
Parameters | |
---|---|
attrs |
AttributeSet |
Returns | |
---|---|
Toolbar.LayoutParams |
getContentInsetEnd
int getContentInsetEnd ()
Gets the ending content inset for this toolbar.
The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.
Related XML Attributes:
Returns | |
---|---|
int |
The ending content inset for this toolbar |
getContentInsetEndWithActions
int getContentInsetEndWithActions ()
Gets the end content inset to use when action buttons are present.
Different content insets are often called for when additional buttons are present
in the toolbar, as well as at different toolbar sizes. The larger value of
getContentInsetEnd()
and this value will be used during layout.
Related XML Attributes:
Returns | |
---|---|
int |
the end content inset used when a menu has been set in pixels |
See also:
getContentInsetLeft
int getContentInsetLeft ()
Gets the left content inset for this toolbar.
The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.
Related XML Attributes:
Returns | |
---|---|
int |
The left content inset for this toolbar |
getContentInsetRight
int getContentInsetRight ()
Gets the right content inset for this toolbar.
The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.
Related XML Attributes:
Returns | |
---|---|
int |
The right content inset for this toolbar |
getContentInsetStart
int getContentInsetStart ()
Gets the starting content inset for this toolbar.
The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.
Related XML Attributes:
Returns | |
---|---|
int |
The starting content inset for this toolbar |
getContentInsetStartWithNavigation
int getContentInsetStartWithNavigation ()
Gets the start content inset to use when a navigation button is present.
Different content insets are often called for when additional buttons are present
in the toolbar, as well as at different toolbar sizes. The larger value of
getContentInsetStart()
and this value will be used during layout.
Related XML Attributes:
Returns | |
---|---|
int |
the start content inset used when a navigation icon has been set in pixels |
See also:
getCurrentContentInsetEnd
int getCurrentContentInsetEnd ()
Gets the content inset that will be used on the ending side of the bar in the current toolbar configuration.
Returns | |
---|---|
int |
the current content inset end in pixels |
See also:
getCurrentContentInsetLeft
int getCurrentContentInsetLeft ()
Gets the content inset that will be used on the left side of the bar in the current toolbar configuration.
Returns | |
---|---|
int |
the current content inset left in pixels |
getCurrentContentInsetRight
int getCurrentContentInsetRight ()
Gets the content inset that will be used on the right side of the bar in the current toolbar configuration.
Returns | |
---|---|
int |
the current content inset right in pixels |
getCurrentContentInsetStart
int getCurrentContentInsetStart ()
Gets the content inset that will be used on the starting side of the bar in the current toolbar configuration.
Returns | |
---|---|
int |
the current content inset start in pixels |
See also:
getLogo
Drawable getLogo ()
Return the current logo drawable.
Returns | |
---|---|
Drawable |
The current logo drawable |
getLogoDescription
CharSequence getLogoDescription ()
Return the description of the toolbar's logo.
Returns | |
---|---|
CharSequence |
A description of the logo |
getMenu
Menu getMenu ()
Return the Menu shown in the toolbar.
Applications that wish to populate the toolbar's menu can do so from here. To use
an XML menu resource, use inflateMenu(int)
.
Returns | |
---|---|
Menu |
The toolbar's Menu |
getNavigationContentDescription
CharSequence getNavigationContentDescription ()
Retrieve the currently configured content description for the navigation button view. This will be used to describe the navigation action to users through mechanisms such as screen readers or tooltips.
Related XML Attributes:
Returns | |
---|---|
CharSequence |
The navigation button's content description |
getNavigationIcon
Drawable getNavigationIcon ()
Return the current drawable used as the navigation icon.
Related XML Attributes:
Returns | |
---|---|
Drawable |
The navigation icon drawable |
getOverflowIcon
Drawable getOverflowIcon ()
Return the current drawable used as the overflow icon.
Returns | |
---|---|
Drawable |
The overflow icon drawable |
getPopupTheme
int getPopupTheme ()
Returns | |
---|---|
int |
resource identifier of the theme used to inflate popup menus, or 0 if menus are inflated against the toolbar theme |
See also:
getSubtitle
CharSequence getSubtitle ()
Return the subtitle of this toolbar.
Returns | |
---|---|
CharSequence |
The current subtitle |
getTitle
CharSequence getTitle ()
Returns the title of this toolbar.
Returns | |
---|---|
CharSequence |
The current title. |
getTitleMarginBottom
int getTitleMarginBottom ()
Related XML Attributes:
Returns | |
---|---|
int |
the bottom title margin in pixels |
See also:
getTitleMarginEnd
int getTitleMarginEnd ()
Related XML Attributes:
Returns | |
---|---|
int |
the ending title margin in pixels |
See also:
getTitleMarginStart
int getTitleMarginStart ()
Related XML Attributes:
Returns | |
---|---|
int |
the starting title margin in pixels |
See also:
getTitleMarginTop
int getTitleMarginTop ()
Related XML Attributes:
Returns | |
---|---|
int |
the top title margin in pixels |
See also:
hasExpandedActionView
boolean hasExpandedActionView ()
Check whether this Toolbar is currently hosting an expanded action view.
An action view may be expanded either directly from the
MenuItem
it belongs to or by user action. If the Toolbar
has an expanded action view it can be collapsed using the collapseActionView()
method.
Returns | |
---|---|
boolean |
true if the Toolbar has an expanded action view |
hideOverflowMenu
boolean hideOverflowMenu ()
Hide the overflow items from the associated menu.
Returns | |
---|---|
boolean |
true if the menu was able to be hidden, false otherwise |
inflateMenu
void inflateMenu (int resId)
Inflate a menu resource into this toolbar.
Inflate an XML menu resource into this toolbar. Existing items in the menu will not be modified or removed.
Parameters | |
---|---|
resId |
int : ID of a menu resource to inflate
|
isOverflowMenuShowing
boolean isOverflowMenuShowing ()
Check whether the overflow menu is currently showing. This may not reflect a pending show operation in progress.
Returns | |
---|---|
boolean |
true if the overflow menu is currently showing |
onRtlPropertiesChanged
void onRtlPropertiesChanged (int layoutDirection)
Parameters | |
---|---|
layoutDirection |
int |
setContentInsetEndWithActions
void setContentInsetEndWithActions (int insetEndWithActions)
Sets the start content inset to use when action buttons are present.
Different content insets are often called for when additional buttons are present
in the toolbar, as well as at different toolbar sizes. The larger value of
getContentInsetEnd()
and this value will be used during layout.
Related XML Attributes:
Parameters | |
---|---|
insetEndWithActions |
int : the inset to use when a menu has been set in pixels |
See also:
setContentInsetStartWithNavigation
void setContentInsetStartWithNavigation (int insetStartWithNavigation)
Sets the start content inset to use when a navigation button is present.
Different content insets are often called for when additional buttons are present
in the toolbar, as well as at different toolbar sizes. The larger value of
getContentInsetStart()
and this value will be used during layout.
Related XML Attributes:
Parameters | |
---|---|
insetStartWithNavigation |
int : the inset to use when a navigation icon has been set
in pixels |
See also:
setContentInsetsAbsolute
void setContentInsetsAbsolute (int contentInsetLeft, int contentInsetRight)
Sets the content insets for this toolbar.
The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.
Related XML Attributes:
Parameters | |
---|---|
contentInsetLeft |
int : Content inset for the toolbar's left edge |
contentInsetRight |
int : Content inset for the toolbar's right edge |
setContentInsetsRelative
void setContentInsetsRelative (int contentInsetStart, int contentInsetEnd)
Sets the content insets for this toolbar relative to layout direction.
The content inset affects the valid area for Toolbar content other than the navigation button and menu. Insets define the minimum margin for these components and can be used to effectively align Toolbar content along well-known gridlines.
Related XML Attributes:
Parameters | |
---|---|
contentInsetStart |
int : Content inset for the toolbar starting edge |
contentInsetEnd |
int : Content inset for the toolbar ending edge |
setLogo
void setLogo (int resId)
Set a logo drawable from a resource id.
This drawable should generally take the place of title text. The logo cannot be
clicked. Apps using a logo should also supply a description using
setLogoDescription(int)
.
Parameters | |
---|---|
resId |
int : ID of a drawable resource
|
setLogo
void setLogo (Drawable drawable)
Set a logo drawable.
This drawable should generally take the place of title text. The logo cannot be
clicked. Apps using a logo should also supply a description using
setLogoDescription(int)
.
Parameters | |
---|---|
drawable |
Drawable : Drawable to use as a logo
|
setLogoDescription
void setLogoDescription (int resId)
Set a description of the toolbar's logo.
This description will be used for accessibility or other similar descriptions of the UI.
Parameters | |
---|---|
resId |
int : String resource id
|
setLogoDescription
void setLogoDescription (CharSequence description)
Set a description of the toolbar's logo.
This description will be used for accessibility or other similar descriptions of the UI.
Parameters | |
---|---|
description |
CharSequence : Description to set
|
setNavigationContentDescription
void setNavigationContentDescription (CharSequence description)
Set a content description for the navigation button if one is present. The content description will be read via screen readers or other accessibility systems to explain the action of the navigation button.
Related XML Attributes:
Parameters | |
---|---|
description |
CharSequence : Content description to set, or null to
clear the content description |
setNavigationContentDescription
void setNavigationContentDescription (int resId)
Set a content description for the navigation button if one is present. The content description will be read via screen readers or other accessibility systems to explain the action of the navigation button.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : Resource ID of a content description string to set, or 0 to
clear the description |
setNavigationIcon
void setNavigationIcon (Drawable icon)
Set the icon to use for the toolbar's navigation button.
The navigation button appears at the start of the toolbar if present. Setting an icon will make the navigation button visible.
If you use a navigation icon you should also set a description for its action using
setNavigationContentDescription(int)
. This is used for accessibility and
tooltips.
Related XML Attributes:
Parameters | |
---|---|
icon |
Drawable : Drawable to set, may be null to clear the icon |
setNavigationIcon
void setNavigationIcon (int resId)
Set the icon to use for the toolbar's navigation button.
The navigation button appears at the start of the toolbar if present. Setting an icon will make the navigation button visible.
If you use a navigation icon you should also set a description for its action using
setNavigationContentDescription(int)
. This is used for accessibility and
tooltips.
Related XML Attributes:
Parameters | |
---|---|
resId |
int : Resource ID of a drawable to set |
setNavigationOnClickListener
void setNavigationOnClickListener (View.OnClickListener listener)
Set a listener to respond to navigation events.
This listener will be called whenever the user clicks the navigation button at the start of the toolbar. An icon must be set for the navigation button to appear.
Parameters | |
---|---|
listener |
View.OnClickListener : Listener to set |
setOnMenuItemClickListener
void setOnMenuItemClickListener (Toolbar.OnMenuItemClickListener listener)
Set a listener to respond to menu item click events.
This listener will be invoked whenever a user selects a menu item from the action buttons presented at the end of the toolbar or the associated overflow.
Parameters | |
---|---|
listener |
Toolbar.OnMenuItemClickListener : Listener to set
|
setOverflowIcon
void setOverflowIcon (Drawable icon)
Set the icon to use for the overflow button.
Parameters | |
---|---|
icon |
Drawable : Drawable to set, may be null to clear the icon
|
setPopupTheme
void setPopupTheme (int resId)
Specifies the theme to use when inflating popup menus. By default, uses the same theme as the toolbar itself.
Parameters | |
---|---|
resId |
int : theme used to inflate popup menus |
See also:
setSubtitle
void setSubtitle (CharSequence subtitle)
Set the subtitle of this toolbar.
Subtitles should express extended information about the current content.
Parameters | |
---|---|
subtitle |
CharSequence : Subtitle to set
|
setSubtitle
void setSubtitle (int resId)
Set the subtitle of this toolbar.
Subtitles should express extended information about the current content.
Parameters | |
---|---|
resId |
int : String resource ID
|
setSubtitleTextAppearance
void setSubtitleTextAppearance (Context context, int resId)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
Parameters | |
---|---|
context |
Context |
resId |
int |
setSubtitleTextColor
void setSubtitleTextColor (int color)
Sets the text color of the subtitle, if present.
Parameters | |
---|---|
color |
int : The new text color in 0xAARRGGBB format
|
setTitle
void setTitle (CharSequence title)
Set the title of this toolbar.
A title should be used as the anchor for a section of content. It should describe or name the content being viewed.
Parameters | |
---|---|
title |
CharSequence : Title to set
|
setTitle
void setTitle (int resId)
Set the title of this toolbar.
A title should be used as the anchor for a section of content. It should describe or name the content being viewed.
Parameters | |
---|---|
resId |
int : Resource ID of a string to set as the title
|
setTitleMargin
void setTitleMargin (int start, int top, int end, int bottom)
Sets the title margin.
Related XML Attributes:
Parameters | |
---|---|
start |
int : the starting title margin in pixels |
top |
int : the top title margin in pixels |
end |
int : the ending title margin in pixels |
bottom |
int : the bottom title margin in pixels |
setTitleMarginBottom
void setTitleMarginBottom (int margin)
Sets the bottom title margin in pixels.
Related XML Attributes:
Parameters | |
---|---|
margin |
int : the bottom title margin in pixels |
See also:
setTitleMarginEnd
void setTitleMarginEnd (int margin)
Sets the ending title margin in pixels.
Related XML Attributes:
Parameters | |
---|---|
margin |
int : the ending title margin in pixels |
See also:
setTitleMarginStart
void setTitleMarginStart (int margin)
Sets the starting title margin in pixels.
Related XML Attributes:
Parameters | |
---|---|
margin |
int : the starting title margin in pixels |
See also:
setTitleMarginTop
void setTitleMarginTop (int margin)
Sets the top title margin in pixels.
Related XML Attributes:
Parameters | |
---|---|
margin |
int : the top title margin in pixels |
See also:
setTitleTextAppearance
void setTitleTextAppearance (Context context, int resId)
Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
Parameters | |
---|---|
context |
Context |
resId |
int |
setTitleTextColor
void setTitleTextColor (int color)
Sets the text color of the title, if present.
Parameters | |
---|---|
color |
int : The new text color in 0xAARRGGBB format
|
showOverflowMenu
boolean showOverflowMenu ()
Show the overflow items from the associated menu.
Returns | |
---|---|
boolean |
true if the menu was able to be shown, false otherwise |
Protected methods
checkLayoutParams
boolean checkLayoutParams (ViewGroup.LayoutParams p)
Parameters | |
---|---|
p |
ViewGroup.LayoutParams |
Returns | |
---|---|
boolean |
generateDefaultLayoutParams
Toolbar.LayoutParams generateDefaultLayoutParams ()
Returns | |
---|---|
Toolbar.LayoutParams |
generateLayoutParams
Toolbar.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)
Parameters | |
---|---|
p |
ViewGroup.LayoutParams |
Returns | |
---|---|
Toolbar.LayoutParams |
onDetachedFromWindow
void onDetachedFromWindow ()
onLayout
void onLayout (boolean changed, int l, int t, int r, int b)
Parameters | |
---|---|
changed |
boolean |
l |
int |
t |
int |
r |
int |
b |
int |
onMeasure
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
Parameters | |
---|---|
widthMeasureSpec |
int |
heightMeasureSpec |
int |
Annotations
Interfaces
- ActionMenuView.OnMenuItemClickListener
- PopupMenu.OnDismissListener
- PopupMenu.OnMenuItemClickListener
- RecyclerView.ChildDrawingOrderCallback
- RecyclerView.ItemAnimator.ItemAnimatorFinishedListener
- RecyclerView.LayoutManager.LayoutPrefetchRegistry
- RecyclerView.OnChildAttachStateChangeListener
- RecyclerView.OnItemTouchListener
- RecyclerView.RecyclerListener
- RecyclerView.SmoothScroller.ScrollVectorProvider
- SearchView.OnCloseListener
- SearchView.OnQueryTextListener
- SearchView.OnSuggestionListener
- ShareActionProvider.OnShareTargetSelectedListener
- ThemedSpinnerAdapter
- Toolbar.OnMenuItemClickListener
Classes
- ActionMenuView
- ActionMenuView.LayoutParams
- AppCompatAutoCompleteTextView
- AppCompatButton
- AppCompatCheckBox
- AppCompatCheckedTextView
- AppCompatEditText
- AppCompatImageButton
- AppCompatImageView
- AppCompatMultiAutoCompleteTextView
- AppCompatRadioButton
- AppCompatRatingBar
- AppCompatSeekBar
- AppCompatSpinner
- AppCompatTextView
- CardView
- DefaultItemAnimator
- DividerItemDecoration
- GridLayout
- GridLayout.Alignment
- GridLayout.LayoutParams
- GridLayout.Spec
- GridLayoutManager
- GridLayoutManager.DefaultSpanSizeLookup
- GridLayoutManager.LayoutParams
- GridLayoutManager.SpanSizeLookup
- LinearLayoutCompat
- LinearLayoutCompat.LayoutParams
- LinearLayoutManager
- LinearLayoutManager.LayoutChunkResult
- LinearSmoothScroller
- LinearSnapHelper
- ListPopupWindow
- OrientationHelper
- PagerSnapHelper
- PopupMenu
- RecyclerView
- RecyclerView.Adapter
- RecyclerView.AdapterDataObserver
- RecyclerView.EdgeEffectFactory
- RecyclerView.ItemAnimator
- RecyclerView.ItemAnimator.ItemHolderInfo
- RecyclerView.ItemDecoration
- RecyclerView.LayoutManager
- RecyclerView.LayoutManager.Properties
- RecyclerView.LayoutParams
- RecyclerView.OnFlingListener
- RecyclerView.OnScrollListener
- RecyclerView.RecycledViewPool
- RecyclerView.Recycler
- RecyclerView.SimpleOnItemTouchListener
- RecyclerView.SmoothScroller
- RecyclerView.SmoothScroller.Action
- RecyclerView.State
- RecyclerView.ViewCacheExtension
- RecyclerView.ViewHolder
- RecyclerViewAccessibilityDelegate
- RecyclerViewAccessibilityDelegate.ItemDelegate
- SearchView
- ShareActionProvider
- SimpleItemAnimator
- SnapHelper
- StaggeredGridLayoutManager
- StaggeredGridLayoutManager.LayoutParams
- SwitchCompat
- ThemedSpinnerAdapter.Helper
- Toolbar
- Toolbar.LayoutParams
- Toolbar.SavedState
- TooltipCompat
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.