我们应该用工具栏替换操作栏吗? [英] Should we replace Action Bar by ToolBar?
问题描述
由于ToolBar
已添加到 Support v7库中,因此我一直在使用它.而且我认为我使用得很好.但是有一点我不明白. Google为什么要创建这样的小部件?我的意思是我们可以使用ActionBar
做ToolBar
可以做的任何事情.为什么我们必须使用ToolBar
? ToolBar
与ActionBar
相比有什么优势?有必要用ToolBar
替换ActionBar
吗?
I have been using ToolBar
since it was added into Support v7 library. And I think I used it well. But there is a point I can't understand. Why would Google create such a widget? I mean we can do anything ToolBar
can do by using ActionBar
. Why do we have to use ToolBar
? What are advantages of ToolBar
over ActionBar
if any? Is it necessary to replace ActionBar
by ToolBar
?
任何提示都值得赞赏.并预先感谢.
Any tips are appreciated. And thanks in advance.
PS:我发现ToolBar
是ViewGroup
的倾析物.那么,如何像Layout
一样使用ToolBar
?有人可以发布一些代码吗?
PS: I found ToolBar
is a decandant of ViewGroup
. So, how could we use ToolBar
like a Layout
? Could somebody post some codes of that?
推荐答案
标准toolbar
用于应用程序内容中.
A standard toolbar
is for use within application content.
A Toolbar
是在应用程序布局中使用的action bar
的概括.虽然action bar
传统上是framework
控制的Activity
不透明window decor
的一部分,但Toolbar
可以放在视图层次结构中的任意嵌套级别.应用程序可以选择使用setActionBar()
方法将Toolbar
指定为Activity
的action bar
.
A Toolbar
is a generalization of action bar
s 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
支持更集中的功能集.从头到尾,toolbar
可能包含以下可选元素的组合:
Toolbar
supports a more focused feature set than ActionBar
. From start to end, a toolbar
may contain a combination of the following optional elements:
- 一个导航按钮.这可能是
Up arrow
,导航菜单切换, 关闭,折叠,完成或应用选择的其他图示符号.这 按钮应始终用于访问其他导航Toolbar
容器内的目的地及其表示 内容或以其他方式保留当前上下文(由Toolbar
.导航按钮在Toolbar
的最小高度(如果已设置). - 品牌徽标图像.这可能会延伸到钢筋的高度,并且 可以任意宽.
- 标题和副标题.标题应该是
Toolbar
在导航层次结构中的当前位置以及 那里包含的内容.subtitle
(如果存在)应指示任何 有关当前内容的扩展信息.如果应用使用logo
image
,应该强烈考虑省略title
和subtitle
. - 一个或多个自定义视图.应用程序可以添加任意子项
Toolbar
的视图.它们将出现在 布局.如果子视图的Toolbar
.LayoutParams
表示Gravity
值CENTER_HORIZONTAL
时,视图将尝试居中 所有其他元素之后Toolbar
中剩余的可用空间 已被测量. - 操作菜单.
menu
动作将固定在Toolbar
提供一些频繁,重要或典型的动作 带有可选的overflow menu
来执行其他操作.Action
按钮 如果已设置,则在Toolbar
的最小高度内垂直对齐.
- 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 theToolbar
and its signified content or otherwise leave the current context signified by theToolbar
. The navigation button is vertically aligned within theToolbar
'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. Thesubtitle
, if present should indicate any extended information about the current content. If an app uses alogo
image
it should strongly consider omitting atitle
andsubtitle
. - 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'sToolbar
.LayoutParams
indicates aGravity
value ofCENTER_HORIZONTAL
the view will attempt to center within the available space remaining in theToolbar
after all other elements have been measured. - An action menu. The
menu
of actions will pin to the end of theToolbar
offering a few frequent, important or typical actions along with an optionaloverflow menu
for additional actions.Action
buttons are vertically aligned within theToolbar
's minimum height, if set.
在现代的Android
UI中,开发人员应该更多地依赖于工具栏的视觉上不同的配色方案,而不是依赖于其应用程序图标.不建议在API 21及更高版本的设备上使用应用程序图标加标题作为标准布局.
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.
这篇关于我们应该用工具栏替换操作栏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!