How to share common layout between activities without fragment

后端 未结 3 1315
挽巷
挽巷 2021-02-02 18:11

Is there any possible way to share layout(part) between activities? For example, in my app, all activities have similar layout, the top part is long operation indicator (a progr

3条回答
  •  旧时难觅i
    2021-02-02 18:52

    You could use include in XML to, well.. include the re-useable part of your layout code.

    As an example, here's my layout file for the Toolbar I used in my app:

    // /res/layout/component_toolbar.xml
    
    
    

    Now, say if I want to use that Toolbar again in a different Activity, this is all I'd have to write:

    // /res/layout/whatever_layout_this_might_be.xml
    
    
    

    Bear in mind that this would only copy the layout - not the actual behavior of said widget/component.

    If you want to actually copy all of the aspects (layout, behaviour) I'm afraid Fragment is the only way to go.

提交回复
热议问题