如何在导航抽屉中添加两个按钮,并在每个按钮上显示不同的菜单项

时间:2019-07-19 09:22:12

标签: android android-layout navigation navigation-drawer drawerlayout

请帮助我制作一个带有两个菜单和两个不同按钮的导航抽屉,以使每个菜单项充气并单击侦听器

下面是模拟,我想像这样制作抽屉 Navigation Drawer First Button View

Navigation Drawer Second Button View

2 个答案:

答案 0 :(得分:1)

请选中this,这将有助于添加自定义视图。您可以使用TabLayout和查看寻呼机

答案 1 :(得分:0)

我已经非常仔细地阅读了您的问题,并尝试进行这种布局。最后我做到了。

尝试使用此代码来实现您的布局

activity_home_navigation_activtiy

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include
    layout="@layout/app_bar_home_navigation_activtiy"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

 <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:fitsSystemWindows="true">


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

        <!--<include layout="@layout/nav_header_home_navigation" />-->

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".28"
            android:background="@color/colorPrimary"
            android:gravity="bottom"
            android:orientation="vertical"
            android:paddingLeft="15dp"
            android:paddingBottom="15dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/navigation_user_img"
                    android:layout_width="65dp"
                    android:layout_height="65dp"
                    android:src="@drawable/ic_launcher_foreground" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/navigation_user_name_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=" Picks App"
                    android:textColor="#504C4C"
                    android:textSize="17dp"
                    android:textStyle="italic" />

                <TextView
                    android:id="@+id/navigation_user_email_tv"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="First Last Name"
                    android:textColor="#000"
                    android:textSize="14sp" />
            </LinearLayout>

        </LinearLayout>

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/navigation_nested"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight=".72"
            android:fillViewport="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="15dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#fff"
                    android:gravity="center"
                    android:orientation="horizontal"
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">

                    <Button
                        android:id="@+id/usr_bt"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:text="User"/>

                    <Button
                        android:id="@+id/admin_bt"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:layout_marginLeft="10dp"
                        android:text="Admin"/>
                </LinearLayout>

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/user_recyler"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="5dp"
                        android:paddingLeft="15dp"
                        android:scrollbars="none" />
                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/admin_recyler"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginBottom="5dp"
                        android:paddingLeft="15dp"
                        android:scrollbars="none" />
                </RelativeLayout>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

    </LinearLayout>

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

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

在这种布局中,我尝试使自定义drawable成为可能。您还可以根据需要进行自定义

查看屏幕截图

Custom Drawable

谢谢