📌  相关文章
📜  Android中的ActionBar和Toolbar之间的区别

📅  最后修改于: 2021-05-10 16:46:28             🧑  作者: Mango

动作栏

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

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

应用程序中的ActionBar:

工具列

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

  • 导航按钮/抽屉或向上按钮
  • 品牌徽标/应用图标
  • 标题和副标题
  • ActionMenu项目
  • 多个自定义视图,例如TextView,ImageView等。

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

差异表

ActionBar

Toolbar

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 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).
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.  
There can be only one ActionBar in an activity. Developers have the choice to show or hide the ActionBar. Multiple Toolbar element having a completely different appearance and behavior can be defined within a single activity. A Toolbar can also be used as an ActionBar.
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.
Google introduced new features in ActionBar gradually. During the release of API 15, 17, and 19 several new features were added to the ActionBar. All features and functionalities were released during the launch of API 21 with the addition of material theme design
Features added at the different API level does not provide backward compatibility.  Provides backward compatibility up to API 7(Android 2.1).
想要一个节奏更快,更具竞争性的环境来学习Android的基础知识吗?
单击此处前往由我们的专家精心策划的指南,以使您立即做好行业准备!