public class Toolbar
extends ViewGroup
| java.lang.Object | |||
| android.view.View | |||
| android.view.ViewGroup | |||
| android.widget.Toolbar | |||
用于应用程序内容的标准工具栏。
工具栏是action bars的泛化, action bars用于应用程序布局。 而动作杆是传统的的一部分Activity's由框架受控不透明窗口装饰,工具栏可以被放置在一个视图体系内的嵌套的任意水平。 应用程序可以选择使用setActionBar()方法将工具栏指定为活动的操作栏。
工具栏支持比ActionBar更集中的功能集。 从开始到结束,工具栏可能包含以下可选元素的组合:
minimum height, if set.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.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.在现代的Android用户界面中,开发人员应该更多地依赖工具栏视觉上不同的颜色方案,而不是其应用程序图标。 应用程序图标和标题作为标准布局的使用在API 21设备和更新版本上是不鼓励的。
Nested classes |
|
|---|---|
class |
Toolbar.LayoutParams 工具栏的子视图的布局信息。 |
interface |
Toolbar.OnMenuItemClickListener 如果项目本身没有单独的项目点击监听器,则负责接收菜单项点击事件。 |
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" 必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。 |
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 |
|
|---|---|
android.view.ViewGroup
|
|
android.view.View
|
|
Inherited constants |
|---|
android.view.ViewGroup
|
android.view.View
|
Inherited fields |
|---|
android.view.View
|
Public constructors |
|
|---|---|
Toolbar(Context context) |
|
Toolbar(Context context, AttributeSet attrs) |
|
Toolbar(Context context, AttributeSet attrs, int defStyleAttr) |
|
Toolbar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) |
|
公共方法(Public methods) |
|
|---|---|
void |
collapseActionView() 折叠当前展开的操作视图。 |
void |
dismissPopupMenus() 关闭当前显示的所有弹出菜单,包括溢出或子菜单。 |
Toolbar.LayoutParams |
generateLayoutParams(AttributeSet attrs) 根据提供的属性集返回一组新的布局参数。 |
int |
getContentInsetEnd() 获取此工具栏的结尾内容插图。 |
int |
getContentInsetEndWithActions() 获取操作按钮存在时插入的结束内容。 |
int |
getContentInsetLeft() 获取此工具栏的左侧内容插图。 |
int |
getContentInsetRight() 获取此工具栏的正确内容插图。 |
int |
getContentInsetStart() 获取此工具栏的起始内容插图。 |
int |
getContentInsetStartWithNavigation() 获取导航按钮存在时的起始内容插图。 |
int |
getCurrentContentInsetEnd() 获取将在当前工具栏配置中的条的结尾侧使用的内容插入。 |
int |
getCurrentContentInsetLeft() 获取将在当前工具栏配置中的栏左侧使用的内容插入。 |
int |
getCurrentContentInsetRight() 获取将在当前工具栏配置中的条右侧使用的内容插入。 |
int |
getCurrentContentInsetStart() 获取将在当前工具栏配置中的条的起始侧使用的内容插入。 |
Drawable |
getLogo() 返回当前可绘制的徽标。 |
CharSequence |
getLogoDescription() 返回工具栏徽标的描述。 |
Menu |
getMenu() 返回工具栏中显示的菜单。 |
CharSequence |
getNavigationContentDescription() 检索导航按钮视图的当前配置的内容描述。 |
Drawable |
getNavigationIcon() 返回用作导航图标的当前绘图。 |
Drawable |
getOverflowIcon() 返回用作溢出图标的当前绘图。 |
int |
getPopupTheme() |
CharSequence |
getSubtitle() 返回此工具栏的副标题。 |
CharSequence |
getTitle() 返回此工具栏的标题。 |
int |
getTitleMarginBottom() |
int |
getTitleMarginEnd() |
int |
getTitleMarginStart() |
int |
getTitleMarginTop() |
boolean |
hasExpandedActionView() 检查此工具栏当前是否托管扩展的操作视图。 |
boolean |
hideOverflowMenu() 隐藏相关菜单中的溢出项目。 |
void |
inflateMenu(int resId) 将菜单资源充入此工具栏。 |
boolean |
isOverflowMenuShowing() 检查当前是否显示溢出菜单。 |
void |
onRtlPropertiesChanged(int layoutDirection) 当任何RTL属性(布局方向或文本方向或文本对齐)已被更改时调用。 |
boolean |
onTouchEvent(MotionEvent ev) 实现此方法来处理触摸屏幕动作事件。 |
void |
setContentInsetEndWithActions(int insetEndWithActions) 设置操作按钮出现时使用的起始内容插图。 |
void |
setContentInsetStartWithNavigation(int insetStartWithNavigation) 设置存在导航按钮时使用的起始内容插图。 |
void |
setContentInsetsAbsolute(int contentInsetLeft, int contentInsetRight) 设置此工具栏的内容插页。 |
void |
setContentInsetsRelative(int contentInsetStart, int contentInsetEnd) 设置此工具栏相对于版面方向的内容插页。 |
void |
setLogo(int resId) 从资源ID中设置可绘制的徽标。 |
void |
setLogo(Drawable drawable) 设置可绘制的徽标。 |
void |
setLogoDescription(int resId) 设置工具栏徽标的说明。 |
void |
setLogoDescription(CharSequence description) 设置工具栏徽标的说明。 |
void |
setNavigationContentDescription(CharSequence description) 为导航按钮设置内容说明(如果存在)。 |
void |
setNavigationContentDescription(int resId) 为导航按钮设置内容说明(如果存在)。 |
void |
setNavigationIcon(Drawable icon) 设置用于工具栏导航按钮的图标。 |
void |
setNavigationIcon(int resId) 设置用于工具栏导航按钮的图标。 |
void |
setNavigationOnClickListener(View.OnClickListener listener) 设置一个监听器来响应导航事件。 |
void |
setOnMenuItemClickListener(Toolbar.OnMenuItemClickListener listener) 设置一个侦听器来响应菜单项点击事件。 |
void |
setOverflowIcon(Drawable icon) 设置用于溢出按钮的图标。 |
void |
setPopupTheme(int resId) 指定充气弹出菜单时要使用的主题。 |
void |
setSubtitle(CharSequence subtitle) 设置此工具栏的副标题。 |
void |
setSubtitle(int resId) 设置此工具栏的副标题。 |
void |
setSubtitleTextAppearance(Context context, int resId) 设置指定TextAppearance资源中的文本颜色,大小,样式,提示颜色和高亮颜色。 |
void |
setSubtitleTextColor(int color) 设置字幕的文本颜色(如果存在)。 |
void |
setTitle(CharSequence title) 设置此工具栏的标题。 |
void |
setTitle(int resId) 设置此工具栏的标题。 |
void |
setTitleMargin(int start, int top, int end, int bottom) 设置标题边距。 |
void |
setTitleMarginBottom(int margin) 以像素为单位设置底部标题边距。 |
void |
setTitleMarginEnd(int margin) 以像素为单位设置结束标题边距。 |
void |
setTitleMarginStart(int margin) 以像素为单位设置起始标题边距。 |
void |
setTitleMarginTop(int margin) 以像素为单位设置顶部标题边距。 |
void |
setTitleTextAppearance(Context context, int resId) 设置指定TextAppearance资源中的文本颜色,大小,样式,提示颜色和高亮颜色。 |
void |
setTitleTextColor(int color) 设置标题的文本颜色(如果存在)。 |
boolean |
showOverflowMenu() 显示相关菜单中的溢出项目。 |
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) |
|
|---|---|
android.view.ViewGroup
|
|
android.view.View
|
|
java.lang.Object
|
|
android.view.ViewParent
|
|
android.view.ViewManager
|
|
android.graphics.drawable.Drawable.Callback
|
|
android.view.KeyEvent.Callback
|
|
android.view.accessibility.AccessibilityEventSource
|
|
要设置为折叠按钮的内容描述的文本。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 collapseContentDescription 。
可用于折叠按钮的图标。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 collapseIcon 。
条内的内容视图的最小插入。 导航按钮和菜单视图除外。 仅适用于某些主题和配置。
必须是尺寸值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 contentInsetEnd 。
相关方法:
当来自菜单的操作存在时,条内的内容视图的最小插入。 仅适用于某些主题和配置。
必须是尺寸值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 contentInsetEndWithActions 。
相关方法:
条内的内容视图的最小插入。 导航按钮和菜单视图除外。 仅适用于某些主题和配置。
必须是一个维度值,它是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 contentInsetLeft 。
相关方法:
条内的内容视图的最小插入。 导航按钮和菜单视图除外。 仅适用于某些主题和配置。
必须是尺寸值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 contentInsetRight 。
相关方法:
条内的内容视图的最小插入。 导航按钮和菜单视图除外。 仅适用于某些主题和配置。
必须是维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 contentInsetStart 。
相关方法:
当存在导航按钮(如“上”按钮)时,条形内的内容视图的最小插入点。 仅适用于某些主题和配置。
必须是尺寸值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 contentInsetStartWithNavigation 。
相关方法:
指定对象应如何在其X轴和Y轴上将其内容定位在其自己的范围内。
必须是以下常量值中的一个或多个(用'|'分隔)。
| Constant | Value | 描述 |
|---|---|---|
top |
0x30 | Push object to the top of its container, not changing its size. |
bottom |
0x50 | Push object to the bottom of its container, not changing its size. |
left |
0x03 | Push object to the left of its container, not changing its size. |
right |
0x05 | Push object to the right of its container, not changing its size. |
center_vertical |
0x10 | Place object in the vertical center of its container, not changing its size. |
fill_vertical |
0x70 | Grow the vertical size of the object if needed so it completely fills its container. |
center_horizontal |
0x01 | Place object in the horizontal center of its container, not changing its size. |
fill_horizontal |
0x07 | Grow the horizontal size of the object if needed so it completely fills its container. |
center |
0x11 | Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. |
fill |
0x77 | Grow the horizontal and vertical size of the object if needed so it completely fills its container. |
clip_vertical |
0x80 | Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges. |
clip_horizontal |
0x08 | Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges. |
start |
0x00800003 | Push object to the beginning of its container, not changing its size. |
end |
0x00800005 | Push object to the end of its container, not changing its size. |
这对应于全局属性资源符号 gravity 。
可以将其设置为出现在工具栏起始处的徽标,位于导航按钮之后。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 logo 。
内容描述字符串,用于描述关联的徽标图像的外观。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 logoDescription 。
要设置为位于工具栏开头的导航按钮的内容描述的文本。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 navigationContentDescription 。
相关方法:
可绘制的图标用于位于工具栏开头的导航按钮。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 navigationIcon 。
相关方法:
引用一个主题,用于对工具栏中的小部件显示的弹出窗口进行充气。
必须是另一个资源的引用,其形式为“ @[+][package:]type:name ”,或者其形式为“一个主题属性 ?[package:][type:]name ”。
这对应于全局属性资源符号 popupTheme 。
指定用于navigationMode =“normal”的字幕文本
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 subtitle 。
应用于字幕字符串的颜色。
必须是“ #rgb ”,“ #argb ”,“ #rrggbb ”或“ #aarrggbb ”形式的颜色值。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 subtitleTextColor 。
与该项目相关的标题。
必须是字符串值,使用'\\;' 转义字符如'\\ n'或'\\ uxxxx'作为unicode字符。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 title 。
在工具栏标题的左侧,开始,右侧和结尾指定额外的空间。 保证金值应该是正值。
必须是维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 titleMargin 。
相关方法:
指定工具栏标题底部的额外空间。 如果指定了此属性和titleMargin,则此属性优先。 保证金值应该是正值。
必须是一个维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 titleMarginBottom 。
相关方法:
指定工具栏标题末尾的额外空间。 如果指定了此属性和titleMargin,则此属性优先。 保证金值应该是正值。
必须是一个维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 titleMarginEnd 。
相关方法:
在工具栏标题的开始侧指定额外的空间。 如果指定了此属性和titleMargin,则此属性优先。 保证金值应该是正值。
必须是维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 titleMarginStart 。
相关方法:
指定工具栏标题顶部的额外空间。 如果指定了此属性和titleMargin,则此属性优先。 保证金值应该是正值。
必须是一个维度值,这是一个浮点数,后面跟着一个单位,例如“ 14.5sp ”。 可用单位为:px(像素),dp(密度独立像素),sp(基于首选字体大小的缩放像素),单位为英寸,毫米(毫米)。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 titleMarginTop 。
相关方法:
要应用于标题字符串的颜色。
必须是“ #rgb ”,“ #argb ”,“ #rrggbb ”或“ #aarrggbb ”形式的颜色值。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name 。
这对应于全局属性资源符号 titleTextColor 。
Toolbar (Context context, AttributeSet attrs)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
Toolbar (Context context, AttributeSet attrs, int defStyleAttr)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
Toolbar (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
| 参数(Parameters) | |
|---|---|
context |
Context
|
attrs |
AttributeSet
|
defStyleAttr |
int
|
defStyleRes |
int
|
void collapseActionView ()
折叠当前展开的操作视图。 如果此工具栏没有展开的操作视图,则此方法不起作用。
操作视图可以直接从它所属的 MenuItem扩展,也可以通过用户操作进行扩展。
也可以看看:
Toolbar.LayoutParams generateLayoutParams (AttributeSet attrs)
根据提供的属性集返回一组新的布局参数。
| 参数(Parameters) | |
|---|---|
attrs |
AttributeSet: the attributes to build the layout parameters from |
| 返回(Returns) | |
|---|---|
Toolbar.LayoutParams |
an instance of ViewGroup.LayoutParams or one of its descendants |
int getContentInsetEnd ()
获取此工具栏的结尾内容插图。
内容嵌入会影响除导航按钮和菜单以外的工具栏内容的有效区域。 插入定义这些组件的最小边距,并可用于沿着着名的网格线有效地对齐工具栏内容。
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
The ending content inset for this toolbar |
int getContentInsetEndWithActions ()
获取操作按钮存在时插入的结束内容。
当工具栏中存在其他按钮时,通常会调用不同的内容插入,以及不同的工具栏大小。 较大的值getContentInsetEnd()和此值将在布局过程中使用。
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
the end content inset used when a menu has been set in pixels |
int getContentInsetLeft ()
获取此工具栏的左侧内容插图。
内容嵌入会影响除导航按钮和菜单以外的工具栏内容的有效区域。 插入定义这些组件的最小边距,并可用于沿着着名的网格线有效地对齐工具栏内容。
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
The left content inset for this toolbar |
int getContentInsetRight ()
获取此工具栏的正确内容插图。
内容嵌入会影响除导航按钮和菜单以外的工具栏内容的有效区域。 插入定义这些组件的最小边距,并可用于沿着着名的网格线有效地对齐工具栏内容。
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
The right content inset for this toolbar |
int getContentInsetStart ()
获取此工具栏的起始内容插图。
内容嵌入会影响除导航按钮和菜单以外的工具栏内容的有效区域。 插入定义这些组件的最小边距,并可用于沿着着名的网格线有效地对齐工具栏内容。
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
The starting content inset for this toolbar |
int getContentInsetStartWithNavigation ()
获取导航按钮存在时的起始内容插图。
当工具栏中存在其他按钮时,通常会调用不同的内容插入,以及不同的工具栏大小。 较大的值getContentInsetStart()和此值将在布局期间使用。
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
the start content inset used when a navigation icon has been set in pixels |
int getCurrentContentInsetEnd ()
获取将在当前工具栏配置中的条的结尾侧使用的内容插入。
| 返回(Returns) | |
|---|---|
int |
the current content inset end in pixels |
int getCurrentContentInsetLeft ()
获取将在当前工具栏配置中的栏左侧使用的内容插入。
| 返回(Returns) | |
|---|---|
int |
the current content inset left in pixels |
int getCurrentContentInsetRight ()
获取将在当前工具栏配置中的条右侧使用的内容插入。
| 返回(Returns) | |
|---|---|
int |
the current content inset right in pixels |
int getCurrentContentInsetStart ()
获取将在当前工具栏配置中的条的起始侧使用的内容插入。
| 返回(Returns) | |
|---|---|
int |
the current content inset start in pixels |
Drawable getLogo ()
返回当前可绘制的徽标。
| 返回(Returns) | |
|---|---|
Drawable |
The current logo drawable |
CharSequence getLogoDescription ()
返回工具栏徽标的描述。
| 返回(Returns) | |
|---|---|
CharSequence |
A description of the logo |
Menu getMenu ()
返回工具栏中显示的菜单。
希望填充工具栏菜单的应用程序可以从此处完成。 要使用XML菜单资源,请使用inflateMenu(int) 。
| 返回(Returns) | |
|---|---|
Menu |
The toolbar's Menu |
CharSequence getNavigationContentDescription ()
检索导航按钮视图的当前配置的内容描述。 这将用于通过屏幕阅读器或工具提示等机制来描述对用户的导航操作。
相关XML属性:
| 返回(Returns) | |
|---|---|
CharSequence |
The navigation button's content description |
Drawable getNavigationIcon ()
返回用作导航图标的当前绘图。
相关XML属性:
| 返回(Returns) | |
|---|---|
Drawable |
The navigation icon drawable |
Drawable getOverflowIcon ()
返回用作溢出图标的当前绘图。
| 返回(Returns) | |
|---|---|
Drawable |
The overflow icon drawable |
int getPopupTheme ()
| 返回(Returns) | |
|---|---|
int |
resource identifier of the theme used to inflate popup menus, or 0 if menus are inflated against the toolbar theme |
也可以看看:
CharSequence getSubtitle ()
返回此工具栏的副标题。
| 返回(Returns) | |
|---|---|
CharSequence |
The current subtitle |
CharSequence getTitle ()
返回此工具栏的标题。
| 返回(Returns) | |
|---|---|
CharSequence |
The current title. |
int getTitleMarginBottom ()
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
the bottom title margin in pixels |
也可以看看:
int getTitleMarginEnd ()
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
the ending title margin in pixels |
也可以看看:
int getTitleMarginStart ()
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
the starting title margin in pixels |
也可以看看:
int getTitleMarginTop ()
相关XML属性:
| 返回(Returns) | |
|---|---|
int |
the top title margin in pixels |
也可以看看:
boolean hasExpandedActionView ()
检查此工具栏当前是否托管扩展的操作视图。
操作视图可以直接从它所属的MenuItem扩展,也可以通过用户操作进行扩展。 如果工具栏具有展开的操作视图,则可以使用collapseActionView()方法将其折叠。
| 返回(Returns) | |
|---|---|
boolean |
true if the Toolbar has an expanded action view |
boolean hideOverflowMenu ()
隐藏相关菜单中的溢出项目。
| 返回(Returns) | |
|---|---|
boolean |
true if the menu was able to be hidden, false otherwise |
void inflateMenu (int resId)
将菜单资源充入此工具栏。
将XML菜单资源充入此工具栏。 菜单中的现有项目将不会被修改或删除。
| 参数(Parameters) | |
|---|---|
resId |
int: ID of a menu resource to inflate |
boolean isOverflowMenuShowing ()
检查当前是否显示溢出菜单。 这可能不会反映正在进行的待处理演出操作。
| 返回(Returns) | |
|---|---|
boolean |
true if the overflow menu is currently showing |
void onRtlPropertiesChanged (int layoutDirection)
当任何RTL属性(布局方向或文本方向或文本对齐)已被更改时调用。 子类需要重写此方法以处理依赖于已解析布局方向的缓存信息,或通知继承其布局方向的子视图。 默认实现什么都不做。
| 参数(Parameters) | |
|---|---|
layoutDirection |
int: the direction of the layout |
boolean onTouchEvent (MotionEvent ev)
实现此方法来处理触摸屏幕动作事件。
如果此方法用于检测点击操作,建议通过执行并调用performClick()来执行操作。 这将确保一致的系统行为,包括:
ACTION_CLICK when accessibility features are enabled | 参数(Parameters) | |
|---|---|
ev |
MotionEvent: The motion event. |
| 返回(Returns) | |
|---|---|
boolean |
True if the event was handled, false otherwise. |
void setContentInsetEndWithActions (int insetEndWithActions)
设置操作按钮出现时使用的起始内容插图。
当工具栏中存在其他按钮时,通常会调用不同的内容插入,以及不同的工具栏大小。 更大的值getContentInsetEnd()和此值将在布局过程中使用。
相关XML属性:
| 参数(Parameters) | |
|---|---|
insetEndWithActions |
int: the inset to use when a menu has been set in pixels |
void setContentInsetStartWithNavigation (int insetStartWithNavigation)
设置存在导航按钮时使用的起始内容插图。
当工具栏中存在其他按钮时,通常会调用不同的内容插入,以及不同的工具栏大小。 在布局过程中将使用较大的值getContentInsetStart()和此值。
相关XML属性:
| 参数(Parameters) | |
|---|---|
insetStartWithNavigation |
int: the inset to use when a navigation icon has been set in pixels |
void setContentInsetsAbsolute (int contentInsetLeft,
int contentInsetRight)
设置此工具栏的内容插页。
内容嵌入会影响除导航按钮和菜单以外的工具栏内容的有效区域。 插入定义这些组件的最小边距,并可用于沿着着名的网格线有效地对齐工具栏内容。
相关XML属性:
| 参数(Parameters) | |
|---|---|
contentInsetLeft |
int: Content inset for the toolbar's left edge |
contentInsetRight |
int: Content inset for the toolbar's right edge |
void setContentInsetsRelative (int contentInsetStart,
int contentInsetEnd)
设置此工具栏相对于版面方向的内容插页。
内容嵌入会影响除导航按钮和菜单以外的工具栏内容的有效区域。 插入定义这些组件的最小边距,并可用于沿着着名的网格线有效地对齐工具栏内容。
相关XML属性:
| 参数(Parameters) | |
|---|---|
contentInsetStart |
int: Content inset for the toolbar starting edge |
contentInsetEnd |
int: Content inset for the toolbar ending edge |
void setLogo (int resId)
从资源ID中设置可绘制的徽标。
这个drawable通常应该代替标题文本。 徽标不能被点击。 使用徽标的应用程序还应使用setLogoDescription(int)提供说明。
| 参数(Parameters) | |
|---|---|
resId |
int: ID of a drawable resource |
void setLogo (Drawable drawable)
设置可绘制的徽标。
这个drawable通常应该代替标题文本。 徽标不能被点击。 使用徽标的应用程序还应使用setLogoDescription(int)提供说明。
| 参数(Parameters) | |
|---|---|
drawable |
Drawable: Drawable to use as a logo |
void setLogoDescription (int resId)
设置工具栏徽标的说明。
此描述将用于UI的可访问性或其他类似描述。
| 参数(Parameters) | |
|---|---|
resId |
int: String resource id |
void setLogoDescription (CharSequence description)
设置工具栏徽标的说明。
此描述将用于UI的可访问性或其他类似描述。
| 参数(Parameters) | |
|---|---|
description |
CharSequence: Description to set |
void setNavigationContentDescription (CharSequence description)
为导航按钮设置内容说明(如果存在)。 内容描述将通过屏幕阅读器或其他辅助功能系统读取,以解释导航按钮的操作。
相关XML属性:
| 参数(Parameters) | |
|---|---|
description |
CharSequence: Content description to set, or null to clear the content description |
void setNavigationContentDescription (int resId)
为导航按钮设置内容说明(如果存在)。 内容描述将通过屏幕阅读器或其他辅助功能系统读取,以解释导航按钮的操作。
相关XML属性:
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a content description string to set, or 0 to clear the description |
void setNavigationIcon (Drawable icon)
设置用于工具栏导航按钮的图标。
导航按钮出现在工具栏的开头(如果存在)。 设置图标将使导航按钮可见。
如果您使用导航图标,则还应使用setNavigationContentDescription(int)为其操作设置说明。 这用于可访问性和工具提示。
相关XML属性:
| 参数(Parameters) | |
|---|---|
icon |
Drawable: Drawable to set, may be null to clear the icon |
void setNavigationIcon (int resId)
设置用于工具栏导航按钮的图标。
导航按钮出现在工具栏的开头(如果存在)。 设置图标将使导航按钮可见。
如果您使用导航图标,则还应使用setNavigationContentDescription(int)为其操作设置说明。 这用于可访问性和工具提示。
相关XML属性:
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a drawable to set |
void setNavigationOnClickListener (View.OnClickListener listener)
设置一个监听器来响应导航事件。
只要用户单击工具栏开始处的导航按钮,就会调用此侦听器。 必须设置图标才能显示导航按钮。
| 参数(Parameters) | |
|---|---|
listener |
View.OnClickListener: Listener to set |
void setOnMenuItemClickListener (Toolbar.OnMenuItemClickListener listener)
设置一个侦听器来响应菜单项点击事件。
只要用户从工具栏末尾提供的操作按钮或关联的溢出中选择一个菜单项,就会调用此侦听器。
| 参数(Parameters) | |
|---|---|
listener |
Toolbar.OnMenuItemClickListener: Listener to set |
void setOverflowIcon (Drawable icon)
设置用于溢出按钮的图标。
| 参数(Parameters) | |
|---|---|
icon |
Drawable: Drawable to set, may be null to clear the icon |
void setPopupTheme (int resId)
指定充气弹出菜单时要使用的主题。 默认情况下,使用与工具栏本身相同的主题。
| 参数(Parameters) | |
|---|---|
resId |
int: theme used to inflate popup menus |
也可以看看:
void setSubtitle (CharSequence subtitle)
设置此工具栏的副标题。
字幕应该表达关于当前内容的扩展信息。
| 参数(Parameters) | |
|---|---|
subtitle |
CharSequence: Subtitle to set |
void setSubtitle (int resId)
设置此工具栏的副标题。
字幕应该表达关于当前内容的扩展信息。
| 参数(Parameters) | |
|---|---|
resId |
int: String resource ID |
void setSubtitleTextAppearance (Context context, int resId)
设置指定TextAppearance资源中的文本颜色,大小,样式,提示颜色和高亮颜色。
| 参数(Parameters) | |
|---|---|
context |
Context
|
resId |
int
|
void setSubtitleTextColor (int color)
设置字幕的文本颜色(如果存在)。
| 参数(Parameters) | |
|---|---|
color |
int: The new text color in 0xAARRGGBB format |
void setTitle (CharSequence title)
设置此工具栏的标题。
标题应该被用作一段内容的锚点。 它应该描述或命名正在查看的内容。
| 参数(Parameters) | |
|---|---|
title |
CharSequence: Title to set |
void setTitle (int resId)
设置此工具栏的标题。
标题应该被用作一段内容的锚点。 它应该描述或命名正在查看的内容。
| 参数(Parameters) | |
|---|---|
resId |
int: Resource ID of a string to set as the title |
void setTitleMargin (int start,
int top,
int end,
int bottom)
设置标题边距。
相关XML属性:
| 参数(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 |
void setTitleMarginBottom (int margin)
以像素为单位设置底部标题边距。
相关XML属性:
| 参数(Parameters) | |
|---|---|
margin |
int: the bottom title margin in pixels |
也可以看看:
void setTitleMarginEnd (int margin)
以像素为单位设置结束标题边距。
相关XML属性:
| 参数(Parameters) | |
|---|---|
margin |
int: the ending title margin in pixels |
也可以看看:
void setTitleMarginStart (int margin)
以像素为单位设置起始标题边距。
相关XML属性:
| 参数(Parameters) | |
|---|---|
margin |
int: the starting title margin in pixels |
也可以看看:
void setTitleMarginTop (int margin)
以像素为单位设置顶部标题边距。
相关XML属性:
| 参数(Parameters) | |
|---|---|
margin |
int: the top title margin in pixels |
也可以看看:
void setTitleTextAppearance (Context context, int resId)
设置指定TextAppearance资源中的文本颜色,大小,样式,提示颜色和高亮颜色。
| 参数(Parameters) | |
|---|---|
context |
Context
|
resId |
int
|
void setTitleTextColor (int color)
设置标题的文本颜色(如果存在)。
| 参数(Parameters) | |
|---|---|
color |
int: The new text color in 0xAARRGGBB format |
boolean showOverflowMenu ()
显示相关菜单中的溢出项目。
| 返回(Returns) | |
|---|---|
boolean |
true if the menu was able to be shown, false otherwise |
boolean checkLayoutParams (ViewGroup.LayoutParams p)
| 参数(Parameters) | |
|---|---|
p |
ViewGroup.LayoutParams
|
| 返回(Returns) | |
|---|---|
boolean |
|
Toolbar.LayoutParams generateDefaultLayoutParams ()
返回一组默认布局参数。 当传递给addView(View)的视图没有设置布局参数时,请求这些参数。 如果返回null,则会从addView引发异常。
| 返回(Returns) | |
|---|---|
Toolbar.LayoutParams |
a set of default layout parameters or null |
Toolbar.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)
根据提供的布局参数返回一组安全的布局参数。 当一个ViewGroup被传递了一个View,其布局参数没有通过checkLayoutParams(android.view.ViewGroup.LayoutParams)的测试时,这个方法被调用。 此方法应该返回一组适合此ViewGroup的布局参数,可能是通过从指定的一组布局参数中复制适当的属性。
| 参数(Parameters) | |
|---|---|
p |
ViewGroup.LayoutParams: The layout parameters to convert into a suitable set of layout parameters for this ViewGroup. |
| 返回(Returns) | |
|---|---|
Toolbar.LayoutParams |
an instance of ViewGroup.LayoutParams or one of its descendants |
void onLayout (boolean changed,
int l,
int t,
int r,
int b)
当这个视图为每个孩子分配一个大小和位置时,从布局调用。 带孩子的派生类应该覆盖这个方法,并调用他们每个孩子的布局。
| 参数(Parameters) | |
|---|---|
changed |
boolean: This is a new size or position for this view |
l |
int: Left position, relative to parent |
t |
int: Top position, relative to parent |
r |
int: Right position, relative to parent |
b |
int: Bottom position, relative to parent |
void onMeasure (int widthMeasureSpec,
int heightMeasureSpec)
测量视图及其内容以确定测量宽度和测量高度。 此方法由measure(int, int)调用, measure(int, int)子类覆盖以提供其内容的准确和有效的度量。
合同:覆盖此方法时,您必须致电setMeasuredDimension(int, int)来存储此视图的测量宽度和高度。 如果不这样做,将触发IllegalStateException ,由measure(int, int)引发。 调用超类' onMeasure(int, int)是一个有效的用法。
Measure的基类实现默认为背景大小,除非MeasureSpec允许更大的大小。 子类应该覆盖onMeasure(int, int)以提供更好的内容度量。
如果此方法被覆盖,则子类的责任是确保测量的高度和宽度至少为视图的最小高度和宽度( getSuggestedMinimumHeight()和 getSuggestedMinimumWidth() )。
| 参数(Parameters) | |
|---|---|
widthMeasureSpec |
int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec. |
heightMeasureSpec |
int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec. |
void onRestoreInstanceState (Parcelable state)
吊钩允许视图重新应用之前由onSaveInstanceState()生成的内部状态的表示。 这个函数永远不会被调用为null状态。
| 参数(Parameters) | |
|---|---|
state |
Parcelable: The frozen state that had previously been returned by onSaveInstanceState(). |
Parcelable onSaveInstanceState ()
钩子允许视图生成其内部状态的表示,稍后可用于创建具有相同状态的新实例。 此状态应仅包含不持久或以后不能重建的信息。 例如,您永远不会将当前位置存储在屏幕上,因为当视图的新实例放置在其视图层次结构中时会再次计算该位置。
您可能在此处存储的某些示例:文本视图中的当前光标位置(但通常不是文本本身,因为它存储在内容提供程序或其他永久性存储中),即当前在列表视图中选择的项目。
| 返回(Returns) | |
|---|---|
Parcelable |
Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null. |