How to put navigation drawer below toolbar?

前端 未结 9 2013
轮回少年
轮回少年 2021-01-02 08:17

Here my navigation drawer is above toolbar.I also added some xml code.Please help me.

here is my activity.xml



        
相关标签:
9条回答
  • 2021-01-02 09:05

    Create a layout like this:

     <android.support.v4.widget.DrawerLayout
            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"
            android:id="@+id/drawer_layout"
            android:layout_width="match_parent"
            android:elevation="4dp"
            android:layout_height="fill_parent"
            >
    
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
    
                >
                <include
                    android:id="@+id/tool_bar"
                    layout="@layout/toolbar"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    />
    
    
                <FrameLayout
                    android:id="@+id/content_frame"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/bg_new">
    
    
        <put your layout here................>
    
                </FrameLayout>
    
    
    
            </LinearLayout>
    
            <android.support.design.widget.NavigationView
                android:id="@+id/navigation"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:fitsSystemWindows="true"
                android:background="@drawable/bg_all"
    
                app:itemIconTint="@android:color/white"
                app:itemTextColor="@android:color/white"
                app:theme="@style/list_item_appearance"
                app:menu="@menu/drawer_menu" >
    
    
            </android.support.design.widget.NavigationView>
        </android.support.v4.widget.DrawerLayout>
    
    0 讨论(0)
  • 2021-01-02 09:12
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:openDrawer="start">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
    
    android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
    
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
       <!--content_main is my layout you can design your own-->
       <!--one more thing is dont put toolbar in your content_main layout-->
        <include layout="@layout/content_main" />
    
        <FrameLayout
            android:id="@+id/content"
            layout="@layout/content_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
        <!-- The navigation drawer -->
        <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:menu="@menu/activity_main_drawer" />
    
    </android.support.v4.widget.DrawerLayout>
    
    
    </LinearLayout>
    
    0 讨论(0)
  • 2021-01-02 09:15

    Your drawer covering your toolbar,to avoid that try below code

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:layout_gravity="start"
            android:background="@android:color/transparent"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/toolBarStyle"
            app:titleTextAppearance="@style/Toolbar.TitleText" />
    
        <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:layout_below="@+id/toolbar"
            android:fitsSystemWindows="true">
    
            <RelativeLayout
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="0dp"
                android:background="@android:color/transparent" />
    
            <fragment
                android:id="@+id/navigation_drawer"
                class="com.buzzintown.consumer.drawer.NavigationDrawerFragment"
                android:layout_width="310dp"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                tools:layout="@layout/drawer_layout" />
        </android.support.v4.widget.DrawerLayout>
    </RelativeLayout>
    
    0 讨论(0)
提交回复
热议问题