This is best example for Common Header Footer in All Activities
BaseActiivty.java
=================
public class BaseActivity extends FragmentActivity {
RelativeLayout mRelativeLayout;
FrameLayout frame_container;
TextView header_txt,footer_txt;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
@Override
public void setContentView(int layoutResID)
{
mRelativeLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
frame_container = (FrameLayout) mRelativeLayout.findViewById(R.id.frame_container);
// set the drawer dialog_view as main content view of Activity.
setContentView(mRelativeLayout);
// add dialog_view of BaseActivities inside framelayout.i.e. frame_container
getLayoutInflater().inflate(layoutResID, frame_container, true);
header_txt = (TextView) findViewById(R.id.header_txt);
footer_txt = (TextView) findViewById(R.id.footer_txt);
}
}
MainActivity.java
=================
public class MainActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
activity_base.xml
=================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_base"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/header_RL"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorAccent">
<TextView
android:id="@+id/header_txt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30dp"
android:gravity="center"
android:text="Header"/>
</RelativeLayout>
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/footer_RL"
android:layout_below="@+id/header_RL">
</FrameLayout>
<RelativeLayout
android:id="@+id/footer_RL"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent">
<TextView
android:id="@+id/footer_txt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30dp"
android:gravity="center"
android:text="Footer"/>
</RelativeLayout>
</RelativeLayout>
activity_main.xml
==================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello World!"
android:textSize="30dp" />
</LinearLayout>
</RelativeLayout>