-2

I am currently using a navigation drawer in one of my apps and want to add a footer space like google does, where I can put a settings and help & FAQ shortcut (just open any google app to find them). I currently am using the code foubd here: https://www.codeofaninja.com/2014/02/android-navigation-drawer-example.html How can I add a footer space to the drawer showed here?

Broadwell
  • 1,343
  • 2
  • 19
  • 33

2 Answers2

0

add one more property to ObjectDrawerItem

public class ObjectDrawerItem {

    public int icon;
    public String name;
    public boolean footer;

    // Constructor.
    public ObjectDrawerItem(int icon, String name,boolean footer) {

        this.icon = icon;
        this.name = name;
        this.footer=footer;
    }
}

then for footer row

drawerItem[2] = new ObjectDrawerItem(R.drawable.ic_action_share, "Help",true);

change listview_item_row.xml to

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:padding="10dp" >

   <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="+@id/rlRow">
    <ImageView
        android:id="@+id/imageViewIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingRight="10dp" />

    <TextView
        android:id="@+id/textViewName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/imageViewIcon"
        android:paddingRight="10dp"
        android:text="Folder name here."
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:textColor="#ffffff" />
 </RelativeLayout>
  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="+@id/rlFooter">
</RelativeLayout>
</RelativeLayout>

finally in adapter getview

if(folder.Footer)
{
(RelativeLayout) listItem.findViewById(R.id.rlFooter).setVisibility(View.Visible);
(RelativeLayout) listItem.findViewById(R.id.rlRow).setVisibility(View.Gone);
}
else
{
(RelativeLayout) listItem.findViewById(R.id.rlFooter).setVisibility(View.Gone);
(RelativeLayout) listItem.findViewById(R.id.rlRow).setVisibility(View.Visible);
}
Durga Mohan
  • 1,110
  • 9
  • 11
0

Add footer in naviagtionview like this

<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#f4f1f1"
        android:fitsSystemWindows="true"
        android:theme="@style/Base.Theme.AppCompat.Light.DarkActionBar"
        android:visibility="visible"
        app:headerLayout="@layout/nav_header_main2"
        app:itemIconTint="@color/colorPrimary"
        app:itemTextAppearance="@style/RobotoTextViewStyle2"
        app:itemTextColor="#000"
        app:menu="@menu/activity_main2_drawer">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:orientation="vertical">

            <View
                android:layout_width="match_parent"
                android:layout_height="1.5dp"
                android:background="#000" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="#f4f1f1"
                android:clickable="true"
                android:gravity="center"
                android:orientation="horizontal">


                <LinearLayout
                    android:id="@+id/share"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/footer_item_1"
                        android:layout_width="40dp"
                        android:layout_height="35dp"
                        android:layout_gravity="center"
                        android:gravity="center"
                        android:padding="5dp"
                        android:src="@drawable/ic_screen_share_black_24dp"
                        android:text="Footer Item 1" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/margin_5"
                        android:fontFamily="@font/noto_serif"
                        android:gravity="center"
                        android:text="Share"
                        android:textColor="#000"
                        android:textSize="@dimen/text_size_12" />

                </LinearLayout>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="@dimen/margin_5"
                    android:layout_marginTop="5dp"
                    android:background="#8c8686" />

                <LinearLayout
                    android:id="@+id/feedback"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/footer_item_2"
                        android:layout_width="40dp"
                        android:layout_height="35dp"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:src="@drawable/ic_feedback_black_24dp"
                        android:text="Footer Item 2" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/margin_5"
                        android:fontFamily="@font/noto_serif"
                        android:gravity="center"
                        android:text="Feedback"
                        android:textColor="#000"
                        android:textSize="@dimen/text_size_12" />
                </LinearLayout>

                <View
                    android:layout_width="0.5dp"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="@dimen/margin_5"
                    android:layout_marginTop="5dp"
                    android:background="#8c8686" />

                <LinearLayout
                    android:id="@+id/rateus"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical">

                    <ImageView
                        android:id="@+id/footer_item_3"
                        android:layout_width="40dp"
                        android:layout_height="35dp"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:padding="5dp"
                        android:src="@drawable/ic_insert_emoticon_black_24dp"
                        android:text="Footer Item 2" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="@dimen/margin_5"
                        android:fontFamily="@font/noto_serif"
                        android:gravity="center"
                        android:text="Rate Us"
                        android:textColor="#000"
                        android:textSize="@dimen/text_size_12" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

    </android.support.design.widget.NavigationView>