0

我是 android 新手,在我的项目中我想添加导航抽屉。我正在选择导航抽屉活动并在 Eclipse 中创建项目请帮助我如何在下面开发导航抽屉

这是项目和子项目菜单的导航抽屉的图像

4

1 回答 1

3

使用导航视图

 <android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"

    app:headerLayout="@layout/nav_header_main_navigation"
    app:itemBackground="@drawable/nav_view_item_background"
    app:itemTextColor="@color/nav_item_text_color"
    app:menu="@menu/activity_main_navigation_drawer" />

activity_main_navigation_drawer 代码

<?xml version="1.0" encoding="utf-8"?>

<group android:checkableBehavior="single" android:id="@+id/root_group">
    <item
        android:id="@+id/item_home"
        android:checked="true"
        android:title="Home" />
    <item android:title="You" android:id="@+id/you_parent_item">
        <menu android:id="@+id/you_menu">
            <group android:checkableBehavior="single" android:id="@+id/you_group">
                <item
                    android:id="@+id/item_you_summary"
                    android:title="Summary Detail" />
                <item
                    android:id="@+id/item_calendar"
                    android:title="Calendar" />
                <item
                    android:id="@+id/item_request_timeout"
                    android:title="Request TimeOut" />
                <item
                    android:id="@+id/item_cancel_requests"
                    android:title="Cancel Requests" />
                <item
                    android:id="@+id/item_approval_responses"
                    android:title="Approval Responses" />
                <item
                    android:id="@+id/item_transaction"
                    android:title="Transactions" />
                <item
                    android:id="@+id/item_approval_request"
                    android:title="Approval Requests" />
                <item
                    android:id="@+id/item_delegate"
                    android:title="Delegate" />
            </group>
        </menu >
    </item>
    <item android:title="Your People" android:id="@+id/your_parent_item">
        <menu android:id="@+id/your_menu">
            <group android:checkableBehavior="single" android:id="@+id/your_group">
                <item
                    android:id="@+id/your_item_sumary"
                    android:title="View Summary" />
                <item
                    android:id="@+id/item_record_timeout"
                    android:title="Record TimeOut" />
            </group>
        </menu>
    </item>
    <item android:title="Settings" android:id="@+id/setting_parent_item">
        <menu android:id="@+id/setting_menu">
            <group android:checkableBehavior="single" android:id="@+id/setting_group">
                <item
                    android:id="@+id/item_log_out"
                    android:title="Log Out" />

            </group>
        </menu>
    </item>
</group>

HeaderLayout 如果你想发送然后

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@color/cws_orange"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

android:theme="@style/Theme.AppTheme.AppBarOverlay">

<ImageView
    android:id="@+id/imgAvatar"
    android:layout_width="40dp"
    android:layout_height="40dp"

    android:src="@android:drawable/sym_def_app_icon" />

<TextView
    android:id="@+id/txtUsername"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/nav_header_vertical_spacing"
    android:text="Android Studio"
    android:textAppearance="@style/TextAppearance.AppCompat.Body1" />

<TextView
    android:id="@+id/txtUserEmail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="android.studio@android.com" />

于 2015-12-31T08:05:44.043 回答