Should we replace the ToolBar action bar?

I used the ToolBar since it was added to the v7 Support library . And I think I used it well. But there is a point that I cannot understand. Why did Google create such a widget? I mean, we can do something that the ToolBar can do using the ActionBar . Why should we use ToolBar ? What are the benefits of the ToolBar over ActionBar , if any? Do I need to replace an ActionBar with a ToolBar ?

Any advice is appreciated. And thanks in advance.

PS: I found that ToolBar is a ViewGroup ViewGroup . So how can we use ToolBar as a Layout ? Can someone post some codes for this?

+53
android android-actionbar android-toolbar
Apr 23 '15 at 4:07
source share
10 answers

The toolbar standard is intended for use in application content.

A toolbar is a generalization of the action bar for use in application layouts. Although the action bar traditionally been part of the Activity opaque window decor managed by the framework , a toolbar can be placed at any arbitrary level of nesting within the view hierarchy. An application can choose to designate a toolbar as an action bar for an Activity using the setActionBar() method.

toolbar supports a more focused feature set than ActionBar . From start to finish, a toolbar may contain a combination of the following optional elements:

  • Navigation button . It can be Up arrow , switching the navigation menu, close, minimize, make or another symbol for selecting an application. This should always be used to access other navigational destinations in the toolbar container and indicate its contents or otherwise leave the current context indicated by the toolbar . The navigation button is vertically aligned within the toolbar minimum height if set.
  • Logo with logo . It can extend to the height of the bar and can be arbitrarily wide.
  • Title and subtitles . The name should be a pointer to the toolbar current position in the navigation hierarchy and contained there. subtitle , if present, should indicate any extended information about the current content. If the application uses a logo image it should strongly consider excluding a title and subtitle .
  • One or more user views . The application can add arbitrary child views on the toolbar . They will appear in this position within the layout. If the child view is a toolbar . LayoutParams indicates a Gravity value of CENTER_HORIZONTAL , the point will try to center inside the remaining space in the toolbar after all other elements have been measured.
  • Action menu . Menu operations will snap to the end toolbar offers several frequent, important or typical actions along with an additional overflow menu for additional actions. The Action buttons are vertically aligned within the minimum height of the toolbar , if set.

In modern Android user interfaces, developers should rely on a visually different color scheme for toolbars than on the icon of their application. Using the app icon plus a title as a standard layout is not recommended on API 21 and newer devices.

+6
May 15 '15 at 2:19
source share

Yes, you should replace ActionBar with a new toolbar

Causes

1) It looks modern and follows a new material design

2) Unlike the action bar, the toolbar is not part of the window decoration. You define it and place it just like any other widget ... so you have the freedom to place it anywhere in the parent layout.

3) You have the freedom to place any widget inside the toolbar.

4) You can define several toolbars.

EDIT

What I meant, you can place other widgets (views) inside the toolbar.

Create a separate layout file for the toolbar (useful for reuse). In my case, the file name is main_toolbar .

  <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:App="http://schemas.android.com/apk/res-auto" xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_width="match_parent" App:theme="@style/ToolbarColoredBackArrow" android:layout_height="56dp" android:background="@color/primary_color" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/drawer_fntsize" android:text="Title" android:id="@+id/lbl_title" android:textColor="@color/title_text_color" android:layout_gravity="center" /> </android.support.v7.widget.Toolbar> 

Then include this toolbar in your main layout, for example,

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/toolbar" layout="@layout/main_toolbar"/> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/toolbar" /> 

As you can see in this example, I placed the TextView inside the toolbar

+31
Apr 23 '15 at 6:04
source share

Why will Android create such a widget?

Imagine an Android tablet if you want.

The application is running on this tablet. This application has a rich text editor in the lower right corner of the screen into which you can enter some comments and format them using bold , italics, etc.

In a desktop or web application, a typical approach for these formatting options, in addition to keyboard shortcuts, will be a toolbar similar to the one you see above the response text area here, in a stack overflow.

Prior to the Toolbar , Android developers had to either collapse their own toolbar, or put formatting actions in an action bar. While the latter approach is simple, it puts a strain on the user of the aforementioned fictional application, as the user must continue to switch his visual focus from the editor (at the bottom of the screen) to the action bar (at the top of the screen).

Why should we use ToolBar?

You do not need to use the Toolbar . I have ~ 300 sample applications as part of my book , and at the moment exactly zero of them use the Toolbar . At some point I will have to fix this, as I have not written the Toolbar chapter yet.

Do I need to replace an ActionBar with a ToolBar?

No. There is a way to do this, but this is optional.

+20
Apr 25 '15 at 19:59
source share

The toolbar is much more flexible than the standard ActionBar, you can add much more tools to the toolbar (as it extends the ViewGroup) and follow the Material Design Guide.

For example, using the toolbar, you can do the following:

My files with big toolbar

A regular ActionBar is not intended to be extended in this way.

In addition, you can better manipulate the contents of the Toolbar, as you can include it in your Action layout XML file. Personally, I use LinearLayout or RelativeLayout at the top, on the toolbar and below, filling in the remaining space, FrameLayout, where my fragments will be added.

Finally, you can put your toolbar anywhere you want, when you install it in your layout file.

UPDATE:

Google has released the Android Design Support Library . The recommended way to get an extended Appbar is to wrap the Toolbar with an AppBarLayout and add an extra view like TabLayout in. To get the FAB in the toolbar, as in this screenshot, you can use the CoordinatorLayout to transfer your layout, and then use the binding attributes in the FAB.

+16
Apr 30 '15 at 15:57
source share

Why should we use ToolBar ?

The toolbar is used for presets and backport compatibility, which are not supported by the old support library. Remember ActionbarSherlock , the android made its own to support the action bar on low-level API devices.

What are the benefits of the ToolBar over ActionBar , if any?

You can easily add a custom view in the XML toolbar as a relative layout view, especially a custom title and animation icons. You have more control options on the toolbar than on the old regular action bar.

Do I need to replace an ActionBar with a ToolBar ?

If you intend to support the action bar on devices below 2.0, then yes, you need back port compatibility for the action bar.

+5
Apr 23 '15 at 4:16
source share
  • You can easily customize the toolbar.
  • You can add many widgets to the toolbar.
  • You can add many toolbars to the panel.
  • You have the freedom to place it anywhere in the parent layout.
  • They have their own management / subview management.
+5
Apr 30 '15 at 5:29
source share

The toolbar is a generalization of action bars for use in application layouts. While the action bar is traditionally part of the non-transparent window design of the Activity, controlled by the wireframe, the toolbar can be placed at any arbitrary level of nesting in the hierarchy of views . An application can choose to designate a toolbar as an action bar for an Activity using the setActionBar () method. You can find more information here . We replaced our action bar as it was easier to customize the toolbar for material design. For example, color palettes and fading animation behavior. Personally, I do not understand why the android discards the old controls and creates a new one. Another example would be a RecyclerView. I don’t understand why they simply did not improve the old API.

+4
Apr 23 '15 at 4:14
source share

Note Both will support general application navigation, icons, and have back support.

The answer depends on what kind of user interaction (animated toolbar) requires your projects. In this case, you must implement the animation on the toolbar to make it a β€œMaterial”.




Actionbar

If you just need a static panel at the top, which may contain icons, a back button and you can use a theme.

Toolbar:

If you want to do something outside of a static panel, like an animation.

The overall implementation and design recommendation for Google is to hide the toolbar when scrolling. Material checklist: hiding scrollbar of application bar?

+4
May 01, '15 at 20:50
source share

Yes

Toolbar support gives you much more flexibility and freedom, with virtually no added cost, that there is no reason why I can think about not making the transition. The transition to the new Toolbar is actually one of the first steps to transfer existing applications to a more material design due to the simplicity of the task and the immediate effect that it has on the overall appearance of the application.

+1
May 01 '15 at 3:13
source share

Here is the link to the documentation - http://developer.android.com/training/appbar/setting-up.html

Note that it does not include code in which you include it in other layout files:

 <include android:id="@+id/toolbar" layout="@layout/tool_bar"/> 

Why I switched to the toolbar. One of the reasons I changed the last application on the Toolbar was that when we wanted to customize the action bar, it would not work on different versions of Android or when we expanded some classes (making it transparent or showing an icon instead of the name of the application ) Toolbars allowed us to customize the options we need.

0
Nov 23 '15 at 10:18
source share



All Articles