Common Header in different activities using BaseActivity in android

前端 未结 4 1520
傲寒
傲寒 2020-12-03 05:10

I want write code once and use in different activities. I have created a Base Activity class for that . Also the header of all the layouts in different activiti

4条回答
  •  执笔经年
    2020-12-03 05:45

    If you are making inheritance with activities and your base activity calls setContentView and after that the real activity calls setContentView the last call will set the layout for activity. So if you are looking for a solution where all activies have the same header component the are 2 ways.

    1. For each activity layout xml you include that component

    2. -You make function for baseActivity e.g. setContent(int layout_id) -You call that with your activity always. -Baseactivity inflates a root view with header and inflates layout_id view to that layout. -Then calls the actual setContentView with that component.

提交回复
热议问题