Writing in the front

In English, bar means shuān, or bar, and I think when you see the word bar you will immediately think of it as a bar. Of course, there are some differences in the definition of bars and latches in Android. Bar in Android has the function of guiding users to quickly let users know the functions and related operations of the current page. Based on this principle, the development history of BAR is as follows.

From the Titlebar to the Actionbar

Before 3.0, Android UI design was relatively simple and rough. At that time, the function definition of bar was also very simple, that is, to display the title of the current page, the name was named Titlebar, which means Titlebar. The bar can also do a single operation, set the title, or add a logo what, more complex you have to customize the View. This bar looks like the picture below, which is downright ugly. It was a mirror image of the beautiful interface on iOS at the time, and it was a testing period for Android, which was all about functionality and nothing else.





Titlebar

At the time, Android was designed to operate with a physical back button, so the Titlebar didn’t even support back. In an era when designs were often tailored to iOS, Android programmers were left to extend the single-purpose Titlebar themselves. I’ve worked hard to emulate the beautiful navigation bar features on iOS apps.

getWindow(a).setFeatureInt(Window.FEATURE_CUSTOM_TITLE.R.layout.custom_title_bar);Copy the code

After several years of development, Android 2.3 version, Android’s major functions are basically stable, the Android community began to have a strong voice for the United States and ease of use. Therefore, In 2011, Google released Version 3.0 of Android, which made major changes in UI design. In addition to introducing the familiar Fragment, It also began to replace Titlebar with Actionbar. The Actionbar, as the name suggests, is no longer just a title, but an Action. The launch of Android3.0 amounts to the end of an old era of trial and error for Android and the beginning of a new era of rapid growth, even though Android3.0 itself has a very small range of applications.

Actionbar era

In addition to displaying titles, the Main function of the Actionbar also provides a consistent navigation and visual experience, highlighting the key actions of the application. For instance you can use SetDisplayHomeAsUpEnabled add up navigation (true), so that when they click the application icon along the left side of the Actionbar returns the parent view.





You can also use Menu to add action buttons to the current page.





You can even customize your View in the Actionbar, like you can





Or add the function of page switching in Actionbar to match the Fragment mechanism





In addition, Actionbar also provides style setting, multi-screen adaptation and other functions. With Titlebar’s pain point fixed, Android finally has its own style for navigation at the top, rather than iOS.

Aha, the Toolbar

With the development of The Times, in 2014, Android5.0 was released, the release of this version marks Android has entered a new era, the era of rapid outbreak has passed, from now on, to become elegant, to have their own unified style. So on this version Google introduced the Material Design language. And then the Actionbar has been reworked, which is easy to use and powerful. However, its biggest drawback is that it is not flexible enough. For example, it defaults to the top, and moving the Actionbar elsewhere on the screen can be cumbersome because it is bound by design to the DecorView. . You can go to the com. Android. Internal policy. See the relevant source DecorView, such as the following section, the Actionbar is fixed on the top, and transverse filling.

mShowPrimaryActionModePopup = new Runnable() {
    public void run() {
        mPrimaryActionModePopup.showAtLocation(
        mPrimaryActionModeView.getApplicationWindowToken(),
            Gravity.TOP | Gravity.FILL_HORIZONTAL, 0, 0);
        endOnGoingFadeAnimation(a); . }};Copy the code

In keeping with the elegant and flexible Design principles of Material Design, Google has created a more flexible Toolbar. You can declare multiple toolbars in one Activity and place them anywhere. And you can stuff any View you want into your Toolbar. The Toolbar is not a replacement for Actionbar; the Toolbar is an extension of the way Actionbar is laid out, just as a child in a family can go out and do more, or go home and continue to be a junior. So you can define a Toolbar and call setActionBar() to make it function as an Actionbar, provided you set the Activity theme or feature to NoActionBar.





Toolbar

For detailed usage of the Toolbar, see Google’s official documentation, which is not covered here.

Address: Pengtao. Me /2017/06/04/…

CPPAlien(@Pengtao Me) is dedicated to making technology easy to understand and fun