【问题标题】:Android add footer to navigation drawerAndroid将页脚添加到导航抽屉
【发布时间】:2015-05-28 13:56:46
【问题描述】:

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

【问题讨论】:

    标签: android navigation footer drawer


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      像这样在导航视图中添加页脚

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多