0

I created a bottom navigation in main activity and does not show menu icon or text

I use the material library version 1.7.0

I changed the version to 1.6.1 and 1.5, but there was still a problem

I invalidate caches and the problem was not solved

I also used the clean project/rebuild project, but the problem was not solved

what is the problem?

activity_main.xml

<layout
    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">
    <data>

    </data>

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <RelativeLayout
            android:id="@+id/mainActivityBase"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.core.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">

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

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/app_name"
                        android:gravity="center"
                        android:textAppearance="?textAppearanceHeadline4"
                        android:layout_marginTop="25dp"/>

                    <androidx.fragment.app.FragmentContainerView
                        android:id="@+id/nav_host_container"
                        android:name="androidx.navigation.fragment.NavHostFragment"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingBottom="64dp"
                        android:clipToPadding="false"
                        app:defaultNavHost="true"
                        app:navGraph="@navigation/nav_movie_player"
                        tools:layout="@layout/fragment_home" />

                </LinearLayout>

            </androidx.core.widget.NestedScrollView>

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottomNavigationMain"
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:layout_alignParentBottom="true"
                android:layout_marginStart="@dimen/marginStart"
                android:layout_marginEnd="@dimen/marginEnd"
                android:layout_marginBottom="@dimen/marginStart"
                android:elevation="8dp"
                app:labelVisibilityMode="unlabeled"
                app:menu="@menu/movie_player_menu"
                app:itemIconSize="28dp"
                app:itemRippleColor="@android:color/transparent"
                />

        </RelativeLayout>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

movie_player_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/homeFragment"
        android:title="@string/home"
        android:icon="@drawable/ic_round_home_24" />

    <item android:id="@+id/searchFragment"
        android:title="@string/search"
        android:icon="@drawable/ic_round_search_24" />

    <item android:id="@+id/profileFragment"
        android:title="@string/profile"
        android:icon="@drawable/ic_round_person_24" />

</menu>

Navigation components setup

 private lateinit var navController: NavController
 private lateinit var appBarConfiguration: AppBarConfiguration

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        binding.lifecycleOwner = this

        setupBottomNavigationBar()
    }

 private fun setupBottomNavigationBar() {
        val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottomNavigationMain)
        val navHostFragment = supportFragmentManager.findFragmentById(
            R.id.nav_host_container
        ) as NavHostFragment
        navController = navHostFragment.navController

        bottomNavigationView.setupWithNavController(navController)
        appBarConfiguration = AppBarConfiguration(
            setOf(R.id.homeFragment, R.id.searchFragment, R.id.profileFragment)
        )

    }

    override fun onSupportNavigateUp(): Boolean {
        return navController.navigateUp(appBarConfiguration)
    }

I run it on a physical phone but the problem was still there

Image

Update

I found the problem set windowTranslucentNavigation false and problem is solved

Amin
  • 35
  • 1
  • 9
  • Are you sure about name of `menu.xml`? it should be `movie_player_menu` because `app:menu="@menu/movie_player_menu"`!! – C.F.G Dec 28 '22 at 14:05
  • Yes, I forgot to write here – Amin Dec 28 '22 at 14:09
  • I deleted empty ` ` in second line and it worked for me. – C.F.G Dec 28 '22 at 14:30
  • I deleted it, but the problem was not solved, and now by increasing the height, I realized that there is padding from the bottom of the auto. I am searching to remove the padding – Amin Dec 28 '22 at 14:36
  • I don't have your `dim` file and I replaced all `"@dimen/margin---"` with `5dp`. Try this for `android:layout_margin ...=5dp` – C.F.G Dec 28 '22 at 14:38
  • margin start , end and bottom is 25dp – Amin Dec 28 '22 at 14:41
  • If you do not use and initialize it with [Navigation Components](https://developer.android.com/guide/navigation), you must bind the menu items to the bottom navigation yourself. Do you use navigation components? – Kozmotronik Dec 28 '22 at 14:44
  • Yes, I use navigation components – Amin Dec 28 '22 at 14:47
  • Can you add the bottom navigation's setup code? – Kozmotronik Dec 28 '22 at 14:52
  • Couldn't detect any bug in your setup. Have you tried setting the bottom navigation's `layout_height` to `wrap_content`? Also, remove all attributes that modify the item properties, including `label_visibility` to see if it makes any difference. You use it inside a `CoordinatorLayout`, therefore you should put `app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"` as well. – Kozmotronik Dec 28 '22 at 15:17
  • I found the problem set windowTranslucentNavigation false and problem is solved – Amin Dec 28 '22 at 20:26

0 Answers0