如何在使用导航抽屉的片段时在底部导航栏上添加导航抽屉?

如何在使用导航抽屉的片段时在底部导航栏上添加导航抽屉?

问题描述:

活动由底部导航栏和片段组成。该片段包含一个导航抽屉,我想要在底部导航抽屉上方可见。如何在使用导航抽屉的片段时在底部导航栏上添加导航抽屉?

什么我是这样的:

我想实现的是这个

我的片段于版图

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

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

+0

显示您的布局XML代码 – Sony

+0

@Sony加我想到了这一点的布局 – Harshit

将您的android.support.design.widget.BottomNavigationView移动到您的content_main。让您的活动将只包含一个视图组,分片将包含抽屉和bottomNavigationView这样

<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> 
+0

。但它需要在每个片段中添加底部导航栏。如果导航栏发生变化,则必须在所有片段中进行更改。没有更清洁的解决方案吗? – Harshit

+0

你可以为你的导航做一个额外的布局,然后包括你想要的任何地方,就像你添加主要内容并添加自定义导航,如果有任何改变 – Sony

+0

我试过了。但是,因为在更换碎片时再次重绘所有内容,所以看起来不那么流畅。所以我换了另一种方式,将导航抽屉添加到主要活动中,然后通过碎片对其进行处理。 无论如何非常感谢您的帮助。 – Harshit