Это мое первое приложение для 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
Тип безопасной навигации заставляет мое приложение сбой ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1745581796
Anonymous
Это мое первое приложение для 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
Подробнее здесь: [url]https://stackoverflow.com/questions/79592392/type-safe-navigation-makes-my-app-to-crash[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия