Akira Kusama
Akira Kusama

Reputation: 55

Hidden Bottom Navigation View regardless of appearing in the xml

Summary

I try to make Bottom Navigation View with Java and android studio.

However, it disappears the bar regardless of showing exact screen in the xml file.


Goal

I'd like to show BottomNavigationView like this video.

Goal screen is below picture.

Goal

Issue

I am coding the video, and done. The xml file is exact screen layout, but when I build the screen, I saw different layout.

Error

What I try
Compared to the code, almost all code isn't different.
Also turn off the fragment code, it works.
I guess the reason why it is disappear must be layout.
However, when I change the number of width or height, it shows same screen.
What's more, when I use layout construction such as Linerlayout, it shows same screen.

Code

activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="@color/white"
    tools:context=".home">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomnavi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:menu="@menu/bottom_menu"/>


        <fragment
            android:id="@+id/fragment2"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="409dp"
            android:layout_height="673dp"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toTopOf="@id/bottomnavi"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:navGraph="@navigation/my_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 0

Views: 534

Answers (1)

Kidus
Kidus

Reputation: 474

It is better if you set the layout_width and layout_height parameter of the fragment to 0dp unless you want it for some reason.

Change these parameters of the <fragment:

android:layout_width="0dp"
android:layout_height="0dp"

Change/Add these parameters of your <com.google.android.material.bottomnavigation.BottomNavigationView:

android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@+id/fragment2"

And see if the problem is fixed.

Upvotes: 1

Related Questions