📌  相关文章
📜  Android中AppBar、ActionBar、Toolbar的区别

📅  最后修改于: 2021-09-15 01:18:44             🧑  作者: Mango

应用栏

AppBar 是应用程序活动中具有重要作用的设计元素。它的外观为应用程序提供了独特的标识。此外,它还显示当前活动的标题,方便用户了解他们在应用程序中的位置。为了使应用程序具有一致的外观,开发人员使用 AppBar。在Android 3.0(Honeycomb) 之前,任何选项或操作等用户交互元素都放置在位于 AppBar的菜单按钮内。 AppBar 中包含的组件包括:

  • 标题
  • 菜单按钮

应用程序中的 AppBar:

操作栏

操作栏 是出现在活动屏幕顶部的元素。这是 android 应用程序的一个显着特征,它在其所有活动中都具有一致的存在。它为应用程序提供了视觉结构,并包含一些用户经常使用的元素。 Android ActionBar 由Google 于 2013 年随着 Android 3.0(API 11)的发布而推出。在此之前,这个最顶级的视觉元素的名称是AppBar 。所有使用 Android 提供的默认主题(Theme.AppCompat.Light.DarkActionBar) 的应用程序,默认都包含一个 ActionBar。但是,开发人员可以根据自己的需要以多种方式对其进行自定义。可以包含在 ActionBar 中的组件有:

  • 导航控制按钮/抽屉
  • 应用程序图标
  • 标题和副标题
  • 操作按钮
  • 动作溢出菜单

应用程序中的 ActionBar:

工具栏

工具栏是一种可以放置在活动的 XML 布局中的ViewGroup。它是由 Google Android 团队在Android Lollipop(API 21)发布期间引入的。 Toolbar 基本上是 ActionBar的高级继承者。它在外观和功能方面更加灵活和可定制。与 ActionBar 不同的是,它的位置不是硬编码的,即不在活动的顶部。开发人员可以根据需要将其放置在 Activity 中的任何位置,就像 android 中的任何其他 View 一样。 Toolbar 使用Android 的 Material Design主题功能,因此它提供了高达API 7(Android 2.1) 的向后兼容性。 Toolbar 支持的功能比 ActionBar 更加集中和可定制。以下是可以添加到工具栏的组件:

  • 导航按钮/抽屉或向上按钮
  • 品牌标志/应用程序图标
  • 标题和副标题
  • 操作菜单项
  • 多个自定义视图,如 TextView、ImageView 等。

应用程序中的 ActionBar(在顶部)和 Toolbar:

差异表

AppBar

ActionBar

Toolbar

It is a dedicated space located at top of an activity that indicates the app title or location of a user in the app. It is a dedicated navigation or control element present at top of each screen of the application. It is a ViewGroup that can be placed anywhere in the activity layout.
It was used in Android devices running on OS version older than 3.0(Honeycomb) It was released along with Android 3.0 (API -11) as the successor of AppBar.   Introduced in material design with the release of Android 5.0 i.e., lollipop(API – 21).
Its position is fixed i.e., at the top of an application screen. It is a part of the activity’s opaque window decor, thus its position is hardcoded. It is the generalized form of ActionBar that can be placed at any arbitrary level within the Component Tree hierarchy of an activity.  
Android system allows the presence of only one AppBar in an activity. There can be only one ActionBar in an activity. Developers have the choice to show or hide the ActionBar. Multiple Toolbar elements having a completely different appearance and the behavior can be defined within a single activity. A Toolbar can also be used as an ActionBar.
Its prime purpose is to provide identity to the application. Further, it includes a Menu button that is used by developers to display relevant options/actions to the user. Behaves as a regular AppBar but provides scope for customization. Developers can add application logo/icon, action menu items, overflow menu, etc. Fewer lines of code are needed to make the same customization in Toolbar that is possible in ActionBar. Moreover, Toolbar provides more flexibility and control to the developers by which they can animate the elements or can apply reaction to scroll events.
With the increase in demand for devices powered with the latest Android versions, developers migrated their design from the Menu button to ActionBar. Features were added gradually, at the different API levels(15, 17, and 19). Thus it does not provide backward compatibility.  Uses material theme design and provides backward compatibility up to API 7(Android 2.1).
想要一个更快节奏和更具竞争力的环境来学习 Android 的基础知识吗?
单击此处前往由我们的专家精心策划的指南,旨在让您立即做好行业准备!