Search code examples
androidandroid-layoutnavigation-drawerbottombar

Why is my BottomBar in the middle of the screen?


I'm using both NavigationDrawer and BottomNavigationView. But after the add Navigation Drawer, position of Bottom Navigation is changed. How do I solve that? I assume this problem is caused by my xml files.

BottomBar

activity_main.xml

<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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
tools:context="com.example.yunus.ototakip.MainActivity">

<include
    layout="@layout/app_bar_navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<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_navigation_bar"
    app:menu="@menu/activity_navigation_bar_drawer" />
<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true">
</FrameLayout>

<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/colorPrimary"
    app:itemIconTint="@color/beyaz"
    app:itemTextColor="@color/beyaz"
    app:menu="@menu/bottombar_menu" />


Solution

  • Attach your BottomNavigationView inside the CoordinatorLayout (or whatever view group you've inside app_bar_navigation_bar layout) not DrawerLayout and add appropriate gravity tag.

    android:layout_gravity="bottom"