BottomNavigationView not showing in my activity

孤街醉人 提交于 2019-12-05 15:47:18
Johan Berg Nilsson

The reason it doesn't work is because menu is in the wrong namespace (design). Use the app namespace instead.

<android.support.design.widget.CoordinatorLayout
    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:background="@color/colorWhite">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_gravity="bottom"
        app:menu="@menu/menu_main" />
</android.support.design.widget.CoordinatorLayout>

Try below xml. Don't forget to add app:layout_anchor and app:layout_anchorGravity="bottom". Here the BottomNavigationView is anchored to the FrameLayout with gravity bottom.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<FrameLayout
    android:id="@+id/rv"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- Contents -->
</FrameLayout>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/nm_bottom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:foregroundTint="@color/colorAccent"
    app:itemIconTint="@android:color/white"
    app:itemTextColor="@android:color/white"
    app:layout_anchor="@+id/rv"
    app:layout_anchorGravity="bottom"
    app:menu="@menu/nav_menu" />

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

I had this problem because my BottomNavigationView was not showing in the design on the android studio. But when I ran the code it appeared on my phone.

So If you did not try running it. Run it and check before you search for answers maybe that is your problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!