如何在菜单项中插入布局以自定义导航抽屉

时间:2018-07-26 20:35:41

标签: android android-layout

我一直试图模仿这个导航抽屉

https://ibb.co/nxqhTo

所以我用过

app:headerLayout="@layout/nav_header_main"

app:menu="@menu/activity_main_drawer"

插入标题和菜单,然后使用

 <item
                android:id="@+id/menu_id"
                app:actionLayout="@layout/action_layout"
                android:title=" " />

在菜单末尾插入一个菜单,使其看起来像图像中的菜单 但是我反而看起来很奇怪 https://ibb.co/fxT818

这是我的菜单代码`

 <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
            tools:showIn="navigation_view"
        >

        <group android:checkableBehavior="single">
            <item
                android:id="@+id/home"
                android:icon="@drawable/ic_home"
                android:title="Home"
                />
            <item
                android:id="@+id/my_profile"
                android:icon="@drawable/ic_profile"
                android:title="My Profile" />
            <item
                android:id="@+id/events"
                android:icon="@drawable/ic_events"
                android:title="Events" />
            <item
                android:id="@+id/favorites"
                android:icon="@drawable/ic_favorites"
                android:title="Favorites" />
            <item
                android:id="@+id/inbox"
                android:icon="@drawable/ic_inbox"
                android:title="Inbox"/>
            <item
                android:id="@+id/menu_seprator"
                android:title=""
                app:actionLayout="@layout/menu_seperator_layout"
                app:showAsAction="ifRoom"/>

            <group android:checkableBehavior="single">
                <item
                    android:id="@+id/nav_share"
                    android:icon="@drawable/ic_contact_us"
                    android:title="Contact us" />
                <item
                    android:id="@+id/nav_send"
                    android:icon="@drawable/ic_feed_back"
                    android:title="Feed back" />
                <item
                    android:id="@+id/settings"
                    android:icon="@drawable/ic_settings"
                    android:title="Settings"/>
            </group>
        </group>

        <item
            android:id="@+id/menu_id"
            app:actionLayout="@layout/action_layout"
            android:title=" " />
    </menu>
    `

     and this is my_action layout that I would like to insert to appear like the header of the navigation view




   <?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="wrap_content"
            android:orientation="vertical"
            android:background="#64192F"
            android:id="@+id/navigation_header_container">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="DASHBOARD"
                android:textColor="@android:color/background_light"
                android:textSize="24sp"
                android:layout_marginLeft="42dp"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
              />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="123dp"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/my_school" />

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/add_school" />

                <ImageView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:src="@drawable/how_to_use_application" />
            </LinearLayout>

        </LinearLayout>

我这里需要的是如何控制导航抽屉菜单内插入的布局的高度和宽度,以便可以像主标题布局一样使用布局自定义抽屉,因此我该如何做。

0 个答案:

没有答案