мне нужна возможность переключать тему в приложении и для этого я написал следующий код: class ThemeManager(private val context: Context) { private val sharedPreferences: SharedPreferences = context.getSharedPreferences("app_preferences", Context.MODE_PRIVATE)


Verify

Open In Editor
Edit
Copy code
var isDarkTheme: Boolean
    get() = sharedPreferences.getBoolean("isDarkTheme", false)
    set(value) {
        sharedPreferences.edit().putBoolean("isDarkTheme", value).apply()
    }
}

@Preview() @OptIn(ExperimentalMaterial3Api::class) @Composable fun SettingsScreen(navController: NavController, themeManager: ThemeManager) { // navController: NavController var warnVisible = remember { mutableStateOf(false) } var checked by remember { mutableStateOf(themeManager.isDarkTheme) } LaunchedEffect(Unit) { checked = themeManager.isDarkTheme }


Verify

Open In Editor
Edit
Copy code
NeureaTheme {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(color = MaterialTheme.colorScheme.surface)
    ) {
        Text("Настройки приложения", color = MaterialTheme.colorScheme.primary, fontWeight = FontWeight.Bold, fontSize = 20.sp,
            modifier = Modifier
                .align(Alignment.CenterHorizontally)
                .padding(vertical = 80.dp))
        Column(
            modifier = Modifier
                .fillMaxSize()
                .clip(RoundedCornerShape(45.dp, 45.dp))
                .background(color = MaterialTheme.colorScheme.secondary)
        ){
            Column(modifier = Modifier
                .padding(start = 40.dp, end = 40.dp, top = 25.dp)
                .clip(shape = RoundedCornerShape(22.dp))
                .border(
                    width = 2.dp,
                    color = MaterialTheme.colorScheme.onSecondary,
                    shape = RoundedCornerShape(24.dp)
                )
                .padding(15.dp),){
                Row(horizontalArrangement = Arrangement.SpaceAround, verticalAlignment = Alignment.CenterVertically){
                    Column(modifier = Modifier
                        .padding(0.dp, 0.dp, 5.dp, 0.dp)
                        .clip(RoundedCornerShape(6.dp))
                    ){
                        Column(modifier = Modifier
                            .background(MaterialTheme.colorScheme.primary)
                            .width(30.dp)
                            .height(30.dp)
                            , horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
                            , ) {
                            Icon(painter = painterResource(id = R.drawable.lighticon), "", tint = MaterialTheme.colorScheme.secondary, modifier = Modifier

                                .height(25.dp)
                                .width(25.dp)
                            )
                        }
                    }

                    Column(modifier = Modifier.width(190.dp)){
                        Text("Темная тема", fontWeight = FontWeight.Medium, fontSize = 14.sp, color=MaterialTheme.colorScheme.onPrimary)
                        Text("Сделать интерфейс приложения темным", fontWeight = FontWeight.Light, fontSize = 12.sp, color=MaterialTheme.colorScheme.onSecondary)
                    }
                    Column(){


                        Switch(
                            checked = checked,
                            onCheckedChange = { checked = it;
                                              themeManager.isDarkTheme=checked}
                            ,
                            modifier = Modifier.padding(10.dp),
                            colors = SwitchDefaults.colors(
                                checkedThumbColor = MaterialTheme.colorScheme.secondary,
                                checkedTrackColor = MaterialTheme.colorScheme.primary,
                                uncheckedThumbColor = MaterialTheme.colorScheme.secondary,
                                uncheckedTrackColor = MaterialTheme.colorScheme.onSecondary,
                                uncheckedBorderColor = Color.Transparent
                                
                            )
                        )
                    }

                }
                    HorizontalDivider(color=MaterialTheme.colorScheme.onSecondary, thickness = 0.5.dp, modifier = Modifier.padding(start = 6.dp, end=6.dp, top = 8.dp, bottom = 17.dp))


                Row(horizontalArrangement = Arrangement.SpaceAround, verticalAlignment = Alignment.CenterVertically){
                    Column(Modifier.width(245.dp)){
                        Text("Выйти из приложения", fontWeight = FontWeight.Medium, fontSize = 14.sp, color=MaterialTheme.colorScheme.onPrimary)
                        Text("По нажатию кнопки вы покинете аккаунт", fontWeight = FontWeight.Light, fontSize = 14.sp, color=MaterialTheme.colorScheme.onSecondary)
                    }
                    Column(modifier = Modifier
                        .padding(0.dp, 0.dp, 5.dp, 0.dp)
                        .clip(RoundedCornerShape(6.dp))
                    ){
                        Column(modifier = Modifier
                            .background(MaterialTheme.colorScheme.primary)
                            .width(30.dp)
                            .height(30.dp)
                            , horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
                            , ) {
                            Icon(painter = painterResource(id = R.drawable.baseline_exit_to_app_24), "", tint = MaterialTheme.colorScheme.secondary, modifier = Modifier

                                .height(25.dp)
                                .width(25.dp)
                            )
                        }
                    }
                }
                HorizontalDivider(color=MaterialTheme.colorScheme.onSecondary, thickness = 0.5.dp, modifier = Modifier.padding(start = 6.dp, end=6.dp, top = 8.dp, bottom = 17.dp))


                Row(horizontalArrangement = Arrangement.SpaceAround, verticalAlignment = Alignment.CenterVertically){
                    Column(Modifier.width(245.dp)){
                        Text("Удалить аккаунт", fontWeight = FontWeight.Medium, fontSize = 14.sp, color=MaterialTheme.colorScheme.onPrimary)
                        Text("По нажатию кнопки вы удалите аккаунт", fontWeight = FontWeight.Light, fontSize = 14.sp, color=MaterialTheme.colorScheme.onSecondary)
                    }
                    Column(modifier = Modifier
                        .padding(0.dp, 0.dp, 5.dp, 0.dp)
                        .clip(RoundedCornerShape(6.dp))
                    ){
                        Column(modifier = Modifier
                            .background(Color(0xFFF15C5C))
                            .width(30.dp)
                            .height(30.dp),
                            horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center
                            , ) {
                            IconButton(onClick = { warnVisible.value = true }) {
                                Icon(painter = painterResource(id = R.drawable.deleteicon), "", tint = MaterialTheme.colorScheme.secondary, modifier = Modifier

                                    .height(25.dp)
                                    .width(25.dp)
                                )
                            }
                        }
                    }
                }


            }



        }



    }
    DeleteAccountWarn(warnVisible.value)
    BottomNav("settingsScreen", navController)
}
} как мне теперь вызвать settingsScreen из навигации и в main activity поставить тему