Skip to content

Commit f50b4b1

Browse files
committed
fix: Android 12 以下 dynamicColorScheme 崩溃,fallback 静态配色
1 parent cef416c commit f50b4b1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

openclaw-android/src/main/java/ai/openclaw/app/ui/OpenClawTheme.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package ai.openclaw.app.ui
22

33
import android.app.Activity
4+
import android.os.Build
45
import androidx.compose.foundation.isSystemInDarkTheme
56
import androidx.compose.material3.MaterialTheme
7+
import androidx.compose.material3.darkColorScheme
68
import androidx.compose.material3.dynamicDarkColorScheme
79
import androidx.compose.material3.dynamicLightColorScheme
10+
import androidx.compose.material3.lightColorScheme
811
import androidx.compose.runtime.Composable
912
import androidx.compose.runtime.CompositionLocalProvider
1013
import androidx.compose.runtime.SideEffect
@@ -17,7 +20,14 @@ import androidx.core.view.WindowCompat
1720
fun OpenClawTheme(content: @Composable () -> Unit) {
1821
val context = LocalContext.current
1922
val isDark = isSystemInDarkTheme()
20-
val colorScheme = if (isDark) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
23+
val colorScheme = when {
24+
// Dynamic colors require Android 12+ (API 31)
25+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
26+
if (isDark) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
27+
}
28+
isDark -> darkColorScheme()
29+
else -> lightColorScheme()
30+
}
2131
val mobileColors = if (isDark) darkMobileColors() else lightMobileColors()
2232

2333
val view = LocalView.current

0 commit comments

Comments
 (0)