我们应该用工具栏替换操作栏吗? [英] Should we replace Action Bar by ToolBar?

查看:93
本文介绍了我们应该用工具栏替换操作栏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于ToolBar已添加到 Support v7库中,因此我一直在使用它.而且我认为我使用得很好.但是有一点我不明白. Google为什么要创建这样的小部件?我的意思是我们可以使用ActionBarToolBar可以做的任何事情.为什么我们必须使用ToolBar? ToolBarActionBar相比有什么优势?有必要用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:我发现ToolBarViewGroup的倾析物.那么,如何像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指定为Activityaction bar.

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 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,应该强烈考虑省略titlesubtitle.
  • 一个或多个自定义视图.应用程序可以添加任意子项 Toolbar的视图.它们将出现在 布局.如果子视图的Toolbar.LayoutParams表示GravityCENTER_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 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.

在现代的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆