How to create a Navigation Drawer and Bottom Bar in the same app
Asked Answered
S

4

11

I am creating an app, and I want to have a Navigation Drawer and a Bottom Bar in the app.

I think that I am going for a good way, but I Can do that the Navigation Drawer when I display it, this is not above the Bottom Bar, it is behind, so How can I do it? I need the Navigation Drawer up of the Bottom Bar.

This is my code, I hope you can help me, thanks n.n

<?xml version="1.0" encoding="utf-8"?>

<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.support.v4.widget.DrawerLayout 
      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
          layout="@layout/include_list_viewpager" />-

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="300dp"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view" />

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


  <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/colorPrimaryRed"
        app:itemTextColor="@drawable/nav_item_color_state"
        app:itemIconTint="@drawable/nav_item_color_state"
        app:menu="@menu/navigation" />


</RelativeLayout>
Somerset answered 10/5, 2017 at 1:47 Comment(1)
T
25
<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <include
       ----- text showing -----/>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"
        app:itemTextColor="@color/colorAccent"
        app:itemIconTint="@color/colorWhite"
        app:menu="@menu/bottom_navigation_item"/>
</RelativeLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />

Twelfth answered 10/5, 2017 at 5:29 Comment(1)
@ter216 try this, if anything else let me knowTwelfth
C
7

You could try

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.chuks.vibefmbenin.MainActivity">

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

    <!-- The main content that loads the fragments -->
    <FrameLayout
        android:id="@+id/frament_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <!-- Setting the corodinator layout inorder to pull the bottom
         navigation view down to the bottom-->
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">  <!--The bottom navigation -->

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigationBottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="?android:attr/windowBackground"
            app:menu="@menu/navigation_bottom"/>

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

    <!-- The navigation drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header">

    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
Cassis answered 15/8, 2017 at 2:49 Comment(0)
S
1

There are two possible solutions to your problem.

  1. It's quite easy. Give your BottomNavigationView a certain height, let's say 56dp and then give this as marginBottom of NavigationView.
  2. Keep it as it is. Just assign your DrawerLayout's property layout_above="@+id/bottom_navigation.
Swett answered 10/5, 2017 at 4:37 Comment(0)
C
0

for me the bottom navigation fails to be positioned at bottom until I try this code

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <include
            layout="@layout/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="?android:attr/windowBackground"
            app:itemBackground="@color/bgBottomNavigation"
            android:foreground="?attr/selectableItemBackground"
            app:itemIconTint="@android:color/white"
            app:itemTextColor="@android:color/white"
            app:menu="@menu/navigation" />
    </android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@android:color/white"
    app:menu="@menu/drawer_view" />

So you can give it try!

and great thanks to

TechTree

for his answer

Cosgrove answered 30/4, 2019 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.