Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 672
ekatz Avatar asked Mar 18 '11 17:03

ekatz


1 Answers

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().

like image 140
Robby Pond Avatar answered Oct 22 '22 03:10

Robby Pond