0

The Bottom Navigation Bar is getting removed after coming back from a fragment which has visibility none for the navigation bar. What to do

This is the fragment in which the bottom navigation is removed

 activity?.findViewById<BottomNavigationView>(R.id.bnb)?.let {
            (it.parent as ViewGroup).removeView(it)
        }

This is main activity

bottomNav.setOnItemSelectedListener setOnNavigationItemSelectedListener@{ item ->
            when(item.itemId){
                R.id.btn1 -> {
                    supportFragmentManager.beginTransaction().replace(R.id.nav_host_fragment_content_main, btn1Fragment()).commit()
                    return@setOnNavigationItemSelectedListener true
                }
                R.id.btn1 -> {
                    supportFragmentManager.beginTransaction().replace(R.id.nav_host_fragment_content_main, FirstFragment()).commit()
                    return@setOnNavigationItemSelectedListener true
                }
                R.id.btn2-> {
                    supportFragmentManager.beginTransaction().replace(R.id.nav_host_fragment_content_main, btn2Fragment()).commit()
                    return@setOnNavigationItemSelectedListener true
                }

                else -> false
            }
            true
        }
  • Your code is showing you permanently removing the bottom bar (there's no coming back after you've called `removeView`. It also shows you manually doing FragmentTransactions on an `R.id.nav_host_fragment` (which is always, always wrong). Is there a reason you aren't following the [example of showing and hiding the bottom nav based on what screen you are on](https://developer.android.com/guide/navigation/navigation-ui#listen_for_navigation_events) and the [bottom navigation with the Navigation Component guide](https://developer.android.com/guide/navigation/navigation-ui#bottom_navigation)? – ianhanniballake Apr 30 '23 at 00:05

0 Answers0