Make fragment layout fullscreen in single activity approach in android

134 Views Asked by At

I have been using the single activity approach and the navigation component. My single activity has a bottom navigation view and one of the bottom view is a RecyclerView. Clicking on one of its items opens a fragment. Let's call it DetailsFragment I would like DetailsFragment to be fullscreen such that the bottom navigation view is not visible anymore. DetailsFragment also has its own toolbar which should hide the activity toolbar as well.

I have read some suggestions to create another activity for DetailsFragment. Doing so is an option which comes with many complex issues as I will have to rewrite all the communications between DetailsFragment and MainActivity.

Best regards.

1

There are 1 best solutions below

0
DeKekem On

This is how I managed to solve the problem:

navController.addOnDestinationChangedListener { _, destination, _ ->
        if (destination.id == R.id.detailFragment) {
            binding.bottomNavigation.visibility = View.GONE
            binding.toolbar.visibility = View.GONE
        } else {
            binding.bottomNavigation.visibility = View.VISIBLE
            binding.toolbar.visibility = View.VISIBLE
        }
    }