0

我正在使用这个材质设计导航抽屉的例子,问题是,当我打开我的抽屉时,它也覆盖了我的操作栏..我的抽屉图标不可见..这是什么我正在getting..and以下是我的代码..导航抽屉涵盖我的工具栏

<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"> 


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

     <LinearLayout 
      android:id="@+id/container_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <include 
       android:id="@+id/toolbar" 
       layout="@layout/toolbar" /> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/container_body" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" /> 


    </LinearLayout> 


    <fragment 
     android:id="@+id/fragment_navigation_drawer" 
     android:name="info.androidhive.materialdesign.activity.FragmentDrawer" 
     android:layout_width="@dimen/nav_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_navigation_drawer" 
     tools:layout="@layout/fragment_navigation_drawer" /> 

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

enter image description here

+2

如果按照材质设计抽屉式导航模式,它实际上应该包括操作栏。 https://www.google.com/design/spec/patterns/navigation-drawer.html –

+0

我希望使用xml查看像fiverr应用程序 –

回答

4

我会建议使用具有垂直取向父的线性布局,然后第一个孩子是你的工具栏和第二你的抽屉布局。

linearlayout vertical 
    toolbar 
    drawerlayout 

希望这会有所帮助。

+1

的帖子,以便它可以帮助其他人 –

0

您可以使用Listview而不是fragment它会在导航栏下面放置导航栏。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      style="@style/MyToolBarStyle.Base" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:minHeight="?attr/actionBarSize" /> 
    </LinearLayout> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <!-- activity view --> 
     <!-- Framelayout to display Fragments --> 
     <FrameLayout 
      android:id="@+id/frame_container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <!-- navigation drawer --> 
     <ListView 
      android:id="@+id/list_slidermenu" 
      android:layout_width="@dimen/slider_dimen" 
      android:layout_height="match_parent" 
      android:layout_gravity="start" 
      android:background="@android:color/white" 
      android:divider="#000" 
      android:dividerHeight="1dp" /> 

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

</LinearLayout> 
2

无论您在android.support.v4.widget.DrawerLayout中有什么,都会被导航抽屉覆盖。看到您的工具栏位于android.support.v4.widget.DrawerLayout,因此它位于导航抽屉下方。所有你需要做的是保持它的android.support.v4.widget.DrawerLayout。这些都是视图,因此请设计您的布局,使您的工具栏高于android.support.v4.widget.DrawerLayout及其子视图。

但是我应该说明,在Android 5.0棒棒糖之后,根据材质指南,导航抽屉应该放在工具栏上。但是你没有必要这样做。

下面是一个例子布局 (然而,理解理论部分是必要的,因为你可以在这之后创建任何类型的布局)

<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

您可以使用xml作为答案发布它会帮助其他人 –

+0

@Lakhan我已经添加了一个示例布局。看到工具栏在DrawerLayout viewGrouo之外。所以抽屉将不会穿过工具栏。 – VipulKumar

1

这是最新的例子导航视图中。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:orientation="vertical"> 

    <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--> 
    <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 with menu items defined in activity_main_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
Modifying your code for the result you expect: 

<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"> 

    <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar" /> 

<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"> 

    <FrameLayout 
     android:id="@+id/container_body" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

    <fragment 
    android:id="@+id/fragment_navigation_drawer" 
    android:name="info.androidhive.materialdesign.activity.FragmentDrawer" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:layout="@layout/fragment_navigation_drawer" 
    tools:layout="@layout/fragment_navigation_drawer" /> 

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

</RelativeLayout> 


Your Welcome...