开发者

Android: Creating a parent layout and extending it to maintain an identical look and feel across all activities of the application

I am writing an app in which I 开发者_运维知识库have mutiple screens which I want to adhere to a certain theme. For example: all screens should have the same background, all screens should have a bar on the top with the same set of actions (not necessarily dependent on the activity currently being show) and all screens should share the same fonts. Is there a way in android to create a parent layout which all other layouts extend and therefore if I need to change some elements (say the background color) I won't have to do it on each individual screen but rather only in the parent screen. I guess what I'm asking is, is there a sort of layout inheritance in android?

Thanks, e.


There is no layout inheritance but you can create this bar layout in a separate file and use include to include it in the layouts that you want to have the bar.

Some of the other stuff could also be done with styles. Create a style for different elements and then add the style to the element in the layouts.

To do inheritance you can create a layout that you can include in other layouts. Then in a BaseActivity you can modify views, add event listeners, etc for the included layout. Just make sure in your onCreate to call setContentView() before you call super.onCreate().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜