Android添加页脚到导航抽屉

时间:2015-05-28 13:56:47

标签: android navigation footer drawer

我目前正在其中一个应用中使用导航抽屉,并希望添加像google一样的页脚空间,我可以在其中设置设置和帮助& FAQ快捷方式(只需打开任何谷歌应用程序即可找到它们)。我目前在这里使用代码foubd:https://www.codeofaninja.com/2014/02/android-navigation-drawer-example.html如何在这里显示的抽屉中添加页脚空间?

2 个答案:

答案 0 :(得分:0)

向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;
    }
}

然后是页脚行

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

listview_item_row.xml更改为

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

最后在适配器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);
}

答案 1 :(得分:0)

在naviagtionview中添加页脚

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