how to remove bottom navigation view and toolbar in some fragments if using navigation controller?

More concise is to use a navigationlistener. This way you only need 1 function in your MainActivity and no code in all the fragments where you want to hide the bottomnavigation or any other UI element (like toolbar). Place this function inside your onCreate from your MainActivity.

My function looks like this:

private fun visibilityNavElements(navController: NavController) {
    navController.addOnDestinationChangedListener { _, destination, _ ->
        when (destination.id) {
            R.id.about_fragment, 
            R.id.settings_fragment, 
            R.id.detail_fragment, 
            R.id.missionPhotoFragment -> bottom_nav?.visibility = View.GONE
            else -> bottom_nav?.visibility = View.VISIBLE
        }
    }
}

I use Kotlin Android Extensions to directly access views by there id (no findViewById needed).