StackOverflowed
StackOverflowed

Reputation: 5975

In Android, using the same toolbar (RelativeLayout elements) across multiple views

I'm in the process of writing a toolbar in one of my views via XML - a toolbar that will be cloned in multiple views. Is there anyway I can reference the same XML in all my views, as opposed to copying and pasting the code? Am I forced to use a Fragment or can I programmatically add the same XML?

Upvotes: 3

Views: 399

Answers (1)

danh32
danh32

Reputation: 6244

You should use the include tag:

http://developer.android.com/resources/articles/layout-tricks-reuse.html

<include layout="@layout/toolbar" />

Edit:

Looks like the link above is now dead, here's a working one: http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html

Upvotes: 8

Related Questions