dark mode-v7

This commit is contained in:
Eric85710 2026-04-23 17:24:30 +08:00
parent acd8f188e2
commit 42872e9ad3
3 changed files with 7 additions and 6 deletions

View file

@ -24,9 +24,7 @@ class MainActivity : ComponentActivity() {
installSplashScreen()
setContent {
val currentAppTheme = themeViewModel.currentTheme.value
Login_V3Theme(appTheme = currentAppTheme) {
Login_V3Theme(appTheme = themeViewModel.currentTheme) {
Technologia()
}
}

View file

@ -21,7 +21,8 @@ import com.example.login_v3.ui.theme.AppTheme
fun setting_theme_page(
viewModel: Theme_ViewModel
){
val selectedTheme = viewModel.currentTheme.value
// 直接讀取,不需要 .value
val selectedTheme = viewModel.currentTheme
Column(modifier = Modifier.padding(16.dp)) {
Text(

View file

@ -1,14 +1,16 @@
package com.example.login_v3.home.setting.setting_detail_page.viewmodel
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.example.login_v3.ui.theme.AppTheme
class Theme_ViewModel : ViewModel() {
var currentTheme = mutableStateOf(AppTheme.SYSTEM)
var currentTheme by mutableStateOf(AppTheme.DARK)
private set
fun updateTheme(newTheme: AppTheme) {
currentTheme.value = newTheme
currentTheme = newTheme
}
}