Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在片段中使用导航抽屉时,如何在底部导航栏上方添加导航抽屉?_Android_Android Layout_Android Fragments - Fatal编程技术网

Android 在片段中使用导航抽屉时,如何在底部导航栏上方添加导航抽屉?

Android 在片段中使用导航抽屉时,如何在底部导航栏上方添加导航抽屉?,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,活动由底部导航栏和片段组成。该片段包含一个导航抽屉,我希望它位于底部导航抽屉的上方 我所拥有的是: 我想要实现的是这一点 我的片段布局- <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://schem

活动由底部导航栏和片段组成。该片段包含一个导航抽屉,我希望它位于底部导航抽屉的上方

我所拥有的是:

我想要实现的是这一点

我的片段布局-

<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
    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"
        android:theme="@style/AppTheme.AppBarOverlay"
        >
        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:local="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

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


<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:paddingTop="?attr/actionBarSize"
    android:layout_gravity="start"
    >
<android.support.v7.widget.RecyclerView
    android:id="@+id/panels_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
</android.support.design.widget.NavigationView>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
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"
tools:context="com.example.harshitaneja.homie.MainActivity">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/navigation_main"
    android:animateLayoutChanges="true"
    android:id="@+id/frame_layout">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/colorPrimary"
    app:itemIconTint="@color/nav_item_state_list"
    app:itemTextColor="@color/nav_item_state_list"
    app:menu="@menu/bottom_navigation_items">

</android.support.design.widget.BottomNavigationView>
</RelativeLayout>

我的活动-

<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
    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"
        android:theme="@style/AppTheme.AppBarOverlay"
        >
        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:local="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

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


<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:paddingTop="?attr/actionBarSize"
    android:layout_gravity="start"
    >
<android.support.v7.widget.RecyclerView
    android:id="@+id/panels_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
</android.support.design.widget.NavigationView>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/activity_main"
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"
tools:context="com.example.harshitaneja.homie.MainActivity">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/navigation_main"
    android:animateLayoutChanges="true"
    android:id="@+id/frame_layout">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/colorPrimary"
    app:itemIconTint="@color/nav_item_state_list"
    app:itemTextColor="@color/nav_item_state_list"
    app:menu="@menu/bottom_navigation_items">

</android.support.design.widget.BottomNavigationView>
</RelativeLayout>


我很抱歉,如果我在问这个问题时犯了任何错误,因为这是我在这里的第一个问题。谢谢

将您的
android.support.design.widget.BottomNavigationView
移动到您的
内容\u main
中。这样,您的活动将只包含一个视图组,片段将包含抽屉和底部导航视图,如下所示

<DrawerLayout>
    <CoordintorLayout>
         <AppBarLayout>
         </AppBarLayout>
         <LinearLayout
          android:orientation="vertical">

          <include layout="@layout/content_main" />

          <android.support.design.widget.BottomNavigationView
              android:id="@+id/navigation_main"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:background="@color/colorPrimary"
              app:itemIconTint="@color/nav_item_state_list"
              app:itemTextColor="@color/nav_item_state_list"
              app:menu="@menu/bottom_navigation_items">

         </LinearLayout>
    </CooorDinatorLayout>
</DrawerLayout>


显示布局xmlcode@Sony添加了布局我想到了这一点。但它需要在每个片段中添加底部导航栏。如果导航栏中有更改,则必须在所有片段中进行更改。难道没有更干净的解决方案吗?你可以为你的导航做一个额外的布局,然后在任何你想要的地方包括,就像你添加主要内容和添加自定义导航一样,如果有任何变化,我尝试过。但因为它在改变碎片时重新绘制了所有的东西,所以看起来不那么流畅。所以我换了一种方式,将导航抽屉添加到主活动中,现在通过片段对其进行操作。无论如何,非常感谢你的帮助。