1
+ package org.ninetripods.mq.study.ui.theme
2
+
3
+ import android.app.Activity
4
+ import androidx.compose.foundation.isSystemInDarkTheme
5
+ import androidx.compose.material.MaterialTheme
6
+ import androidx.compose.material.darkColors
7
+ import androidx.compose.material.lightColors
8
+ import androidx.compose.runtime.Composable
9
+ import androidx.compose.runtime.SideEffect
10
+ import androidx.compose.ui.graphics.toArgb
11
+ import androidx.compose.ui.platform.LocalView
12
+ import androidx.core.view.WindowCompat
13
+
14
+ private val DarkColorScheme = darkColors(
15
+ primary = Purple80 ,
16
+ secondary = PurpleGrey80 ,
17
+ // tertiary = Pink80
18
+ )
19
+
20
+ private val LightColorScheme = lightColors(
21
+ primary = Purple40 ,
22
+ secondary = PurpleGrey40 ,
23
+ // tertiary = Pink40
24
+
25
+ /* Other default colors to override
26
+ background = Color(0xFFFFFBFE),
27
+ surface = Color(0xFFFFFBFE),
28
+ onPrimary = Color.White,
29
+ onSecondary = Color.White,
30
+ onTertiary = Color.White,
31
+ onBackground = Color(0xFF1C1B1F),
32
+ onSurface = Color(0xFF1C1B1F),
33
+ */
34
+ )
35
+
36
+ @Composable
37
+ fun AndroidStudyTheme (
38
+ darkTheme : Boolean = isSystemInDarkTheme(),
39
+ // Dynamic color is available on Android 12+
40
+ dynamicColor : Boolean = true,
41
+ content : @Composable () -> Unit ,
42
+ ) {
43
+ val colorScheme = when {
44
+ // dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
45
+ // val context = LocalContext.current
46
+ // if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
47
+ // }
48
+
49
+ darkTheme -> DarkColorScheme
50
+ else -> LightColorScheme
51
+ }
52
+ val view = LocalView .current
53
+ if (! view.isInEditMode) {
54
+ SideEffect {
55
+ val window = (view.context as Activity ).window
56
+ window.statusBarColor = colorScheme.primary.toArgb()
57
+ WindowCompat .getInsetsController(window, view)?.isAppearanceLightStatusBars = darkTheme
58
+ }
59
+ }
60
+
61
+ MaterialTheme (
62
+ // colorScheme = colorScheme,
63
+ typography = Typography ,
64
+ content = content
65
+ )
66
+ }
0 commit comments