Это мое первое приложение для Android. В настоящее время я работаю над навигационной частью. Теперь проблема заключается в том, что когда я нажимаю кнопку «Добавить» (Iconbutton), чтобы перейти на экран «Добавить заметки», приложение сбоя, я не знаю, почему, и я тоже искал в Интернете. Но все еще не смог найти решение.class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Enables drawing content edge-to-edge (allows the content to appear behind system bars)
enableEdgeToEdge()
// Sample list of notes to populate the grid
val title = "Note Title"
val description = "While this approach works, it's not an ideal way to " +
"architect your app. A benefit of using a NavHost to handle your" +
" app's navigation is that navigation logic is kept separate from individual UI."
val sampleNotes = listOf(
Note(1, title, description, PeachySunrise), // PeachySunrise
Note(2, title, description, SkyBliss), // SkyBliss
Note(3, title, description, BlushBloom), // BlushBloom
Note(4, title, description, MintMeadow), // MintMeadow
Note(5, title, description, SunbeamGlow), // SunbeamGlow
Note(6, title, description, LavenderHaze), // LavenderHaze
Note(7, title, description, FrostyMist), // FrostyMist
Note(8, title, description, RoseCoral), // RoseCoral
Note(9, title, description, VanillaCream), // VanillaCream
Note(10, title, description, CloudWhisper) // CloudWhisper
)
setContent {
NotesTheme {
val navController = rememberNavController()
SystemBarColor(
statusBarColor = Color.Transparent,
navigationBarColor = Color.Transparent,
darkIcons = true // This makes status bar icons dark (for light themes)
)
NavHost(
navController = navController,
startDestination = Home
) {
composable {
// Surface fills the entire screen with a white background
Surface(
modifier = Modifier.fillMaxSize(),
color = Color.White
) {
TopBar()
NotesGrid(notes = sampleNotes)
}
}
composable {
// Surface fills the entire screen with a white background
Surface(
modifier = Modifier.fillMaxSize(),
color = Color.White
) {
Header()
}
}
}
}
}
}
}
// Create a composable for system bar configuration
@Composable
fun SystemBarColor(
statusBarColor: Color = Color.Transparent,
navigationBarColor: Color = Color.Transparent,
darkIcons: Boolean = true
) {
val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.setStatusBarColor(
color = statusBarColor,
darkIcons = darkIcons
)
systemUiController.setNavigationBarColor(
color = navigationBarColor,
darkIcons = darkIcons
)
}
}
@Serializable
object Home
@Serializable
object AddNote
Подробнее здесь: https://stackoverflow.com/questions/795 ... p-to-crash