Should we replace Action Bar by ToolBar?

后端 未结 10 1516
日久生厌
日久生厌 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:34

    Yes, you should replace ActionBar with new toolbar.

    Reasons

    1. It looks modern and it follows new material design.

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

    3. You have freedom to put any widget inside toolbar.

    4. You can define multiple toolbars.

    EDIT

    What i meant is you can place other widgets (views) inside toolbar.

    Create a separate layout file for the toolbar (good for reusability). In my case file name is main_toolbar.xml

    
    
    
        
    
     
    

    Then include this toolbar in your main layout like this

    
    
    
        
    
        
    
    
    

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

提交回复
热议问题