Should we replace Action Bar by ToolBar?

后端 未结 10 1529
日久生厌
日久生厌 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.

提交回复
热议问题