工具栏下方的左导航菜单和工具栏上的右导航菜单

时间:2016-06-16 04:38:35

标签: android drawerlayout android-navigation-drawer

我在抽屉布局中有两个导航菜单,。我想要工具栏下方的左导航菜单和工具栏上的右导航菜单,如下图所示:

enter image description here

如何实现这一目标?

我的布局是:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/id_home_start"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:scrollbars="vertical">
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    tools:context="com.artifex.mupdfdemo.HomeStart">
    <include
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        layout="@layout/toolbar_layout" />

</LinearLayout>


    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:id="@+id/home_menu"
        android:layout_gravity="start">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            card_view:cardUseCompatPadding="true">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:src="@drawable/upld"
                    android:layout_marginLeft="1dp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/my_uploads"
                    android:text="My Uploads"
                    android:textColor="#000000"
                    android:textStyle="bold"
                    android:textSize="20dp"
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp"
                    android:gravity="center"
                    />
            </LinearLayout>
        </android.support.v7.widget.CardView>

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


    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/profile_menu"
        android:layout_gravity="end">
        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            card_view:cardUseCompatPadding="true">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:src="@drawable/options"
                    android:layout_marginLeft="1dp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/update_profile"
                    android:text="Update Profile"
                    android:textColor="#000000"
                    android:textStyle="bold"
                    android:textSize="20dp"
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp"
                    android:gravity="center"
                    />
            </LinearLayout>
        </android.support.v7.widget.CardView>


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

我的Java代码是:

Toolbar toolbar;
    DrawerLayout drawerLayout;
    ActionBarDrawerToggle actionBarDrawerToggle;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_start);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle("Home");
        setSupportActionBar(toolbar);
        drawerLayout = (DrawerLayout) findViewById(R.id.id_home_start);
        actionBarDrawerToggle=new ActionBarDrawerToggle(this,  drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
        drawerLayout.setDrawerListener(actionBarDrawerToggle);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState){
        super.onPostCreate(savedInstanceState);
        actionBarDrawerToggle.syncState();
    }

1 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/id_home_start"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.artifex.mupdfdemo.HomeStart">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:background="@color/primary"
                android:minHeight="?attr/actionBarSize"
                card_view:layout_scrollFlags="scroll|enterAlways"
                card_view:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                card_view:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        </android.support.design.widget.AppBarLayout>

    </LinearLayout>


    <android.support.design.widget.NavigationView
        android:id="@+id/home_menu"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:layout_marginTop="?attr/actionBarSize">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            card_view:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginLeft="1dp"
                    android:src="@drawable/btn_theme_bg_effect" />

                <TextView
                    android:id="@+id/my_uploads"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:paddingBottom="10dp"
                    android:paddingTop="10dp"
                    android:text="My Uploads"
                    android:textColor="#000000"
                    android:textSize="20dp"
                    android:textStyle="bold" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

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


    <android.support.design.widget.NavigationView
        android:id="@+id/profile_menu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="end">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            card_view:cardUseCompatPadding="true">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginLeft="1dp"
                    android:src="@drawable/btn_theme_bg_effect" />

                <TextView
                    android:id="@+id/update_profile"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:paddingBottom="10dp"
                    android:paddingTop="10dp"
                    android:text="Update Profile"
                    android:textColor="#000000"
                    android:textSize="20dp"
                    android:textStyle="bold" />
            </LinearLayout>
        </android.support.v7.widget.CardView>


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