I've just started to get familiar with Jetpack Compose and from what I understand, a NavHost is like a NavHostFragment, it hosts different composables rather than fragments.
What I'm struggling to understand is that if I define a screen with a scaffold and a NavHost as its content like:
setContent{
Scaffold(...){
NavHost(...){...}
}
}
That makes the bottom nav bar and everything defined in the scaffold appear for every single composable hosted by the NavHost. What if I want to have different floating action buttons for different screens? Do I have to start a new activity for those screens and define a different scaffold there?
You can actually reference the navHostController. You can either keep track of the current screen by updating a variable everytime you navigate or just use navController.getCurrentBackStackEntry?.destination to get the current screen. Use this inside your floating action button to set it accordingly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.