How to create a generic Android XML layout for all activities

前端 未结 3 1840
无人共我
无人共我 2020-12-16 02:12

I have an application that needs the same items [5 buttons acting as tabs] in every screen. Is it possible to create a \"base XML layout\" that has these 5 buttons and then

3条回答
  •  -上瘾入骨i
    2020-12-16 03:06

    You may want to look in to the tag. It effectively takes an xml that you created and copy and pastes it in to your other layouts.

    So what you would do is create a single layout with your button. Put them between a tag so they do not create a FrameLayout to get placed in. Then put use the tag to use the same layout in your other layouts.

    NOTE: Always override the layout_width and layout_height attributes when using the tag. This is true even if you are overriding them when the same values. There is a bug in previous versions of Android where it would ignore certain attributes if you didn't override those attributes as well.

提交回复
热议问题