androidkotlinandroid-navigationandroid-viewbindingandroid-navigationview

how to make visibility = View.GONE a certain view when launching a certain fragment when using navigation and BottomNavView


main_actiity.class

activity_main XML photo

main_fragment.class

fragment_main XML photo

enter image description here


Solution

  • This can be easily done by subscribing to navigation component destination change listener, like this:

    navController.addOnDestinationChangedListener { controller, destination, arguments ->
        if(destination.id = R.id.yourMainFragment) {
            // TODO hide/show your view here
        }
    }
    

    And then hiding/showing based on destination