For the More Curious: App Bar vs Action Bar vs Toolbar

You will often hear people refer to the app bar as the toolbar or the action bar. And the official Android documentation uses these terms interchangeably. But are the app bar, action bar, and toolbar really the same thing? In short, no. The terms are related, but they are not exactly equivalent.

The UI design element itself is called an app bar. Prior to Android 5.0 (Lollipop, API level 21), the app bar was implemented using the ActionBar class. The terms action bar and app bar came to be treated as one and the same. Starting with Android 5.0 (Lollipop, API level 21), the Toolbar class was introduced as the preferred method for implementing the app bar.

As of this writing, AppCompat uses the Jetpack Toolbar widget to implement the app bar (Figure 14.14).

Figure 14.14  Layout inspector view of app bar

Layout inspector view of app bar

The ActionBar and Toolbar are very similar components. The toolbar builds on top of the action bar. It has a tweaked UI and is more flexible in the ways that you can use it.

The action bar has many constraints. It will always appear at the top of the screen. There can only be one action bar. The size of the action bar is fixed and should not be changed. The toolbar does not have these constraints.

In this chapter, you used a toolbar that was provided by one of the AppCompat themes. Alternatively, you can manually include a toolbar as a normal view in your activity or fragment’s layout file. You can place this toolbar anywhere you like, and you can even include multiple toolbars on the screen at the same time. This flexibility allows for interesting designs; for example, imagine if each fragment that you use maintained its own toolbar. When you host multiple fragments on the screen at the same time, each of them could bring along its own toolbar instead of sharing a single toolbar at the top of the screen.

Another interesting addition with the toolbar is the ability to place Views inside the toolbar and also to adjust the height of the toolbar. This allows for much more flexibility in the way that your app works.

Equipped with this bit of history about the app bar-related APIs, you are now armed to more easily navigate the official developer documentation about this topic. And perhaps you can even spread the love and help clarify the overlap in these terms to future Android developers, since it is very confusing without the historical perspective.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
44.213.65.97