I want that this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView android:id="@+id/logo" style="@style/logo"
android:layout_alignParentTop="true"
android:text="@string/logo" tools:context=".MainActivity" />
to start in every layout. How can I do that I wouldn’t need to add this to every layout page? Like for example in PHP I would use <?=include("header.php");?> (just an example, actually it’s bad practise, doesn’t matter here). Thank you.
Save your header in XML file and then include this XML as child layout in other layouts:
The headerlayout.xml is name of your above layout that should be defined in
res/layoutand you like that be shown as header in all layouts(layout="@layout/headerlayout"),also headerLayoutid is id of your headerlayout(in it’s parent) and you can reference to it in your parent layouts or in your code.You can override all the layout parameters. This means that any
android:layout_*attribute can be used with the tag. Here is an example:You can see more details in about include in this page.
Edit:
If you have problems in about finding views in included layout,see this questions,I hope these help you:
findViewById not working for an include?
Finding an view by id?