Android: the system bars follow the app's theme, not the phone's
enableEdgeToEdge() picks the bar icons from the system's night mode, so the dark theme of the app on a light phone left dark icons on a dark bar. The bars are set again with the theme chosen in the app whenever it changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b88e339f0b
commit
0ca444ed8d
2 changed files with 21 additions and 0 deletions
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
All notable changes are listed here. Versions follow [Semantic Versioning](https://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Android: the status bar and the navigation bar follow the theme chosen in the app: with
|
||||
the dark theme on a light phone their icons are light again (they stayed dark on dark).
|
||||
|
||||
## [0.13.0] — 2026-10-23
|
||||
|
||||
- Android: **game report** — ⋮ → «Game analysis» lets Stockfish evaluate every move of the
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.graphics.Color
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
|
|
@ -12,12 +14,17 @@ import androidx.compose.material3.MaterialTheme
|
|||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import io.github.vrubelroman.chesspenguin.data.Language
|
||||
import io.github.vrubelroman.chesspenguin.data.Theme
|
||||
import io.github.vrubelroman.chesspenguin.theme.ChessPenguinTheme
|
||||
|
||||
/// The scrims behind three-button navigation, as `enableEdgeToEdge` has them by default.
|
||||
private val LIGHT_SCRIM = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
|
||||
private val DARK_SCRIM = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun attachBaseContext(base: Context) {
|
||||
super.attachBaseContext(Language.wrap(base))
|
||||
|
|
@ -36,6 +43,15 @@ class MainActivity : ComponentActivity() {
|
|||
Theme.Light -> false
|
||||
Theme.Dark -> true
|
||||
}
|
||||
// The system bars follow the theme chosen in the app, not the system's: light
|
||||
// icons over a dark app even when the phone itself is light, and back.
|
||||
DisposableEffect(dark) {
|
||||
enableEdgeToEdge(
|
||||
statusBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT) { dark },
|
||||
navigationBarStyle = SystemBarStyle.auto(LIGHT_SCRIM, DARK_SCRIM) { dark },
|
||||
)
|
||||
onDispose {}
|
||||
}
|
||||
ChessPenguinTheme(darkTheme = dark) {
|
||||
Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { MainNavigation() }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue