0% found this document useful (0 votes)
7 views1 page

Navegacion Jetpack

The document outlines a simple Android application using Jetpack Compose for navigation between two screens. It defines a MainActivity that sets up a NavHost with two composable functions: pantallaInicio and pantallaDetalle, which allow navigation between a main screen and a detail screen. The application features buttons that facilitate the navigation between these two screens.

Uploaded by

spenserfer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Navegacion Jetpack

The document outlines a simple Android application using Jetpack Compose for navigation between two screens. It defines a MainActivity that sets up a NavHost with two composable functions: pantallaInicio and pantallaDetalle, which allow navigation between a main screen and a detail screen. The application features buttons that facilitate the navigation between these two screens.

Uploaded by

spenserfer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

//implementation("androidx.navigation:navigation-compose:2.4.

0-alpha09")
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
navega()
}
}
}
@Preview
@Composable
fun navega()
{
//////NavController y NavHost
val navController= rememberNavController()
NavHost(navController=navController, startDestination = "principal")
{
composable ("principal") {
pantallaInicio(navController=navController)
}
composable ("pantalla2") {
pantallaDetalle(navController=navController)
}
}
}
@Composable
fun pantallaInicio(navController: NavController)
{
Button(onClick = {navController.navigate("pantalla2") },
colors = ButtonDefaults.buttonColors(containerColor =Color.Yellow))
{
Text("detalle")
}
}
@Composable
fun pantallaDetalle(navController: NavController)
{
Button(onClick = { navController.navigate("principal") })
{
Text("principal")
}
}

You might also like