Should we replace Action Bar by ToolBar?

后端 未结 10 1468
日久生厌
日久生厌 2020-12-12 19:11

I have been using ToolBar since it was added into Support v7 library. And I think I used it well. But there is a point I can\'t understand. Why

相关标签:
10条回答
  • 2020-12-12 19:41

    Toolbar is much more flexible than standard ActionBar, you can add much more tools in a Toolbar (as it extends ViewGroup), and follow Material Design Guidelines.

    For example, with a Toolbar, you can do the following :

    My Files with big toolbar

    A regular ActionBar isn't intended to be expanded this way.

    Also, you can better manipulate Toolbar content as you can include it in your Activity layout xml file. Personally, I use a LinearLayout or a RelativeLayout with at the top, the Toolbar, and below, filling the leftover space, a FrameLayout where my Fragments will be added.

    Finally, you can place your Toolbar anywhere you want as you set it in your layout file.

    UPDATE:

    Google released Android Design Support Library. The recommended way to get an extended Appbar is to wrap Toolbar with AppBarLayout, and add additional view such as TabLayout in. To get a FAB over the Toolbar like in this screenshot, you can use CoordinatorLayout to wrap your layout content, and then use anchor attributes on the FAB.

    0 讨论(0)
  • 2020-12-12 19:43

    Yes

    The support Toolbar gives you so much more flexibility and freedom, at practically no added extra cost, that there's no reason I can think of not to make the transition. Transitioning to the new Toolbar is actually one of the first steps to porting existing apps to a more Material design, due to the simplicity of the task, and the immediate effect it has on the overall look and feel of the app.

    0 讨论(0)
  • 2020-12-12 19:45

    Why have we to use ToolBar?

    Toolbar is use for pre-devices and backport compatibility that the old support library does not provide. Remember ActionbarSherlock, android made there own to support actionbar on low level API devices.

    What are advantages of ToolBar over ActionBar if any?

    You can easy add custom view with in the XML of toolbar like a relative layout view, specially a custom title and icons with animations. You have more control on your toolbar rather than the old conventional actionbar.

    Is it necessary to replace ActionBar by ToolBar?

    If you are going to support actionbar on devices lower than 2.0 then yes, you need a back-port compatibility for action bar.

    0 讨论(0)
  • 2020-12-12 19:50

    A standard toolbar is for use within application content.

    A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy. An application may choose to designate a Toolbar as the action bar for an Activity using the setActionBar() method.

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

    • A navigation button. This may be an Up arrow, navigation menu toggle, close, collapse, done or another glyph of the app's choosing. This button should always be used to access other navigational destinations within the container of the Toolbar and its signified content or otherwise leave the current context signified by the Toolbar. The navigation button is vertically aligned within the Toolbar's minimum height, if set.
    • A branded logo image. This may extend to the height of the bar and can be arbitrarily wide.
    • A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.
    • One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout. If a child view's Toolbar.LayoutParams indicates a Gravity value of CENTER_HORIZONTAL the view will attempt to center within the available space remaining in the Toolbar after all other elements have been measured.
    • An action menu. The menu of actions will pin to the end of the Toolbar offering a few frequent, important or typical actions along with an optional overflow menu for additional actions. Action buttons are vertically aligned within the Toolbar's minimum height, if set.

    In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

    0 讨论(0)
提交回复
热议问题