Sanjana Nair
Sanjana Nair

Reputation: 2785

Footer in All screens in Android

I have created a footer I would like to show the footer on all the screens I am also showing NavigationDrawer. How do I show the footer in all the screens?

The include in NavgaitionDrawer doesn't show the footer at all? Can somebody help me fix this:

Below is the XML file that shows the toolbar etc.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/button_material_light"
    android:orientation="vertical" >

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/navigationHost"
        android:layout_width="match_parent"
        android:background="@color/button_material_light"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/parentContentHost"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <FrameLayout
                android:id="@+id/contentHost"
                android:layout_width="match_parent"
                android:foreground="?android:windowContentOverlay"
                android:layout_height="match_parent" />

        </LinearLayout>

        <include
            layout="@layout/n_drawerlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:layout_marginRight="10dp" />

    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

Thanks!

Upvotes: 1

Views: 161

Answers (2)

jonathanrz
jonathanrz

Reputation: 4296

From your comment, I understood that what you really want is to add the footer to the end of the screen, so here is what you need to accomplish it:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/button_material_light"
    android:orientation="vertical" >

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/navigationHost"
        android:layout_width="match_parent"
        android:background="@color/button_material_light"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/parentContentHost"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <FrameLayout
                android:id="@+id/contentHost"
                android:layout_width="match_parent"
                android:foreground="?android:windowContentOverlay"
                android:layout_height="0dp"
                android:layout_weight="1"/>

            <include
                android:id="@+id/footer"
                layout="@layout/footer" />

        </LinearLayout>

        <include
            layout="@layout/n_drawerlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:layout_marginRight="10dp" />

    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

But if you want to add this footer for every activity, you will need to add the footer in the xml of each activity or add it programatically in a BaseActivity class.

Upvotes: 2

marc97
marc97

Reputation: 128

If you have various activities where you have to show the footer you can achieve that using the tag <include layout="@layout/your_footer"> in all of your root xml activity files.

Upvotes: 0

Related Questions