How to add header and footer to every action in android

I want to add ImageButtona buttonand a textviewin each of my actions above and below. I was thinking about using header and footer. So I want to add a header and footer to each of my Android operations. I do not know how to do that. I don't need the source code for writing a header or footer. I want to know where I have to determine that the headers and footers mean that I need to add headers and footers to each XML file or I need to define two header.xmlor footer.xmland use these xml files in each other xml files. Or is there another way, for example, to use the link from the java file of this activity. Any help appreciated.

+3
source share
6 answers

Define two separate files header.xmland footer.xmland use

`

<include layout="@layout/footer"/>
+9
source

See this link:

This is exactly the same as your question. If you want to have this header and footer, you must create a custom view and use it in your application. You can use something like an action bar as a title.

+4
source

" header.xml footer.xml XML xml "

, , . include xml XML . :

...
<include layout="@layout/header"/>
...
<include layout="@layout/footer"/>
...
+2

Android . , , , ():

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

, , .

http://developer.android.com/training/improving-layouts/reusing-layouts.html

+2

. .

+1
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>
+1

All Articles