Skip to content

fix(android): follow system theme so WebView sees correct prefers-color-scheme - #301

Merged
ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/aw-android-system-theme
Sep 23, 2026
Merged

ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/aw-android-system-theme

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

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, this
value 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 the
Activity into light mode regardless of the OS setting. So prefers-color-scheme
always 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:

  1. AWApplication.kt (new): calls AppCompatDelegate.setDefaultNightMode( MODE_NIGHT_FOLLOW_SYSTEM) in Application.onCreate(). This wires the
    process-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.

  2. styles.xml: changes AppTheme parent from
    Theme.AppCompat.Light.NoActionBar to Theme.AppCompat.DayNight.NoActionBar
    so the theme properly responds to the night mode configuration.

  3. values-night/colors.xml: adds default_text_color = #FFFFFF so the
    existing android:textColor override in AppTheme doesn't produce black text
    on 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 AppCompatDelegate to prevent Activity recreation
and WebView reload. That concern applies to switching the night mode while
the app is running. Setting MODE_NIGHT_FOLLOW_SYSTEM in Application.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 Application
  • Existing WebUiThemeTest and MainActivityNavigationTest unchanged

…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
@greptile-apps

greptile-apps Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The implementation appears safe to merge; the remaining issue is non-blocking test coverage that does not exercise manifest registration or startup night-mode behavior.

Summary

This PR makes the Android activity follow the system night-mode configuration so WebView receives the correct prefers-color-scheme value.

  • Registers a custom Application that selects MODE_NIGHT_FOLLOW_SYSTEM before activities start.
  • Changes the application theme from AppCompat Light to DayNight.
  • Keeps native Auth, Sync, and Onboarding text black against their explicitly light backgrounds.
  • Adds unit coverage for the application class, AppCompat constant, and absence of a night text-color override.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Application process starts] --> B[AWApplication.onCreate]
    B --> C[Set MODE_NIGHT_FOLLOW_SYSTEM]
    C --> D[Activity starts with DayNight configuration]
    D --> E[WebView reads prefers-color-scheme]
    D --> F[Native screens apply chrome]
    F --> G[Auth / Sync / Onboarding remain light]
    F --> H[MainActivity matches Web UI scheme]
Loading

Reviews (2) · Last reviewed commit: "fix(android): keep native-screen text re..."

Comment thread mobile/src/main/res/values-night/colors.xml Outdated
Comment thread mobile/src/test/java/net/activitywatch/android/AWApplicationTest.kt
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
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
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.

@ErikBjare
ErikBjare merged commit 6e4e92d into ActivityWatch:master Sep 23, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App fails to follow system theme and falls back to light theme

2 participants