The layout I want to achieve is the following:
- Three (3) destinations on the bottom app bar
- The first destination ( HOME ) has bottons to access other destinations, for example a settings screen which is opened in full screen.
Here is the code I have now adapted from the docs:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberNavController()
Scaffold(
bottomBar = { NavBar(navController = navController) }
) { paddingValues ->
NavHost(
navController = navController,
startDestination = Screen.Overview.route,
modifier = Modifier.padding(paddingValues),
) {
composable(route = Screen.Overview.route) {
OverviewScreen() <--- this screen can access other screens
}
composable(route = Screen.Transactions.route) {
TransactionsScreen()
}
}
}
}
}
}
Inside the overview screen, I have the following:
@Composable
fun OverviewScreen(
modifier: Modifier = Modifier,
) {
val overviewNavController = rememberNavController()
NavHost(navController = overviewNavController,
startDestination = <--- current screen IS the main screen of this graph
){
composable(route = Screen.Settings.route){
SettingsScreen()
}
...
}
This code works correctly but for example the settings screen should NOT have the buttom bar visible! Hence I cannot declare them within the main NavHost graph.
How to achieve this ? What construct allows me to do this? I don't mind restructuring the entire code. Thanks in advance.
I have made an example for you. I have used Material3 And Latest Android Studio Version.
Just Replace You Drawable Icon
Example