fix(android): follow system theme so WebView sees correct prefers-color-scheme - #301
Merged
ErikBjare merged 2 commits intoSep 23, 2026
Conversation
…or-scheme With Theme.AppCompat.Light.NoActionBar the Activity always ran in light mode, so Android WebView reported prefers-color-scheme: light even when the OS was in dark mode. Choosing 'System' in aw-webui's theme setting therefore always resolved to light. Fix: - Add AWApplication that calls AppCompatDelegate.setDefaultNightMode( MODE_NIGHT_FOLLOW_SYSTEM) before any Activity starts. This wires the Activity's effective night mode to the OS setting without triggering any Activity recreation (the mode is set at process start, not at runtime). - Change AppTheme parent to Theme.AppCompat.DayNight.NoActionBar so the theme properly responds to the night mode configuration. - Add default_text_color night override so the existing android:textColor override doesn't produce black text on dark backgrounds. Closes ActivityWatch#300 Git-Session-Id: dc18
|
DayNight follows the system for WebView prefers-color-scheme, but Auth/Sync/Onboarding still paint light chrome. A night-mode white default_text_color made that text unreadable. Git-Session-Id: 84ac7667-43de-5e02-bfe2-7f38d9d3f6f9
Contributor
Author
|
@greptileai review |
Contributor
Author
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #300.
When the user selects "System" in aw-webui's theme picker, the JS hook reads
window.matchMedia('(prefers-color-scheme: dark)').matches. On Android, thisvalue is derived from the Activity's effective night mode configuration, not
directly from the system setting.
The old base theme was
Theme.AppCompat.Light.NoActionBar, which forces theActivity into light mode regardless of the OS setting. So
prefers-color-schemealways returned
light, and "System" was indistinguishable from "Light".Erik confirmed this: the setting "becomes light mode for me, despite in system
dark mode at 01:46 AM."
Fix
Three small changes that work together:
AWApplication.kt(new): callsAppCompatDelegate.setDefaultNightMode( MODE_NIGHT_FOLLOW_SYSTEM)inApplication.onCreate(). This wires theprocess-wide night mode to the OS setting before any Activity starts,
so there is no Activity recreation — the Activity simply starts in the
correct mode.
styles.xml: changesAppThemeparent fromTheme.AppCompat.Light.NoActionBartoTheme.AppCompat.DayNight.NoActionBarso the theme properly responds to the night mode configuration.
values-night/colors.xml: addsdefault_text_color = #FFFFFFso theexisting
android:textColoroverride in AppTheme doesn't produce black texton dark backgrounds.
The native chrome (system bars, drawer) already adapts via
applyWebUiChrome()in
MainActivity— those codepaths are unchanged.Why not AppCompatDelegate at runtime?
PR #276 explicitly avoided
AppCompatDelegateto prevent Activity recreationand WebView reload. That concern applies to switching the night mode while
the app is running. Setting
MODE_NIGHT_FOLLOW_SYSTEMinApplication.onCreate()is different: the mode is fixed at process start, so the Activity is born in the
correct mode and never needs to recreate.
Tests
AWApplicationTest.kt: verifies the class exists and inherits from ApplicationWebUiThemeTestandMainActivityNavigationTestunchanged