Si se está usando el componente Navigation component componente del Jetpack(AndroidX) de Gooogle
Añadir el fragment bottom_sheet en el gráfico de navegación nav_host, crear los enlaces correspondientes desde donde queremos que sea llamado
Mostrar un BottomSheetFragment
Para motrar un BottomSheetFragment usando Navigation Component, primero debemos obtener el identificador de navegación del fragment bottom_sheet, por ejemplo R.id.action_bottomSheetFragment
v.findNavController().navigation(R.id.action_bottomSheetFragment)
Pasando argumentos
Usando argumentos, previamente se juntan todos mediante un bundle, que se llena de forma clave/valor "key" to value
val titulo : String = "Titulo Bottom Sheet)
val bundle = bundleOf("ARG_TITULO" to titulo)
Para abrir el bottom sheet usando el navigation component y argumentos, se hace de la misma forma pero añadiendo el bundle
v.findNavController().navigation(R.id.action_bottomSheetFragment, bundle)
Para leer el argumento dentro del bottom sheet Fragment se hace con arguments?.
arguments?.getString(ARG_TITULO)
Navegar a otro destino
Si queremos abrir otro destino desde el Bottom Sheet Fragment usando en Navigation component,
NavHostFragment.findNavController(this).navigation(R.id.nuevo_destino)
Un comentario en “Abrir BottomSheetFragment con Navigation component”