Description
On Android a WebView inherits the theme of the app (which initially defaults to the theme of the system) but on Windows it does not (I suspect it inherits the system theme directly, but I have not checked).
So, on Android 35+ an App that controls its own theme will have that theme reflected in an embedded WebView but on Windows 11 it will not.
Because I have a workaround this a low priority issue for me.
Steps to Reproduce
- Clone the test repo
- Build and run it on Android 35+ running with the default light theme.
- You should see this:
- Tap "Switch to web page" and observe the page is black text on a white background.
- Go back to the main page and switch the app to dark mode.
- Tap "Switch to web page" and observe the page is white text on a black background.
- Repeat on Windows - the web page theme will not change when the app theme changes.
Link to public reproduction project repository
https://github.com/david-maw/web-theme.git
Version with bug
10.0.50
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
No response
Affected platforms
Windows
Affected platform versions
Windows 11, Android 35+
Did you find any workaround?
Yes, before showing the web page explicitly set the WebView2 theme:
#if WINDOWS
if (webView.Handler?.PlatformView is Microsoft.UI.Xaml.Controls.WebView2 wv)
{
bool isDark = App.Current?.RequestedTheme == AppTheme.Dark;
await wv.EnsureCoreWebView2Async();
wv.CoreWebView2.Profile.PreferredColorScheme =
isDark
? Microsoft.Web.WebView2.Core.CoreWebView2PreferredColorScheme.Dark
: Microsoft.Web.WebView2.Core.CoreWebView2PreferredColorScheme.Light;
}
#endif
This code is in the reproduction code guarded with a compile-time WORKAROUND define.
Relevant log output
Description
On Android a WebView inherits the theme of the app (which initially defaults to the theme of the system) but on Windows it does not (I suspect it inherits the system theme directly, but I have not checked).
So, on Android 35+ an App that controls its own theme will have that theme reflected in an embedded WebView but on Windows 11 it will not.
Because I have a workaround this a low priority issue for me.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/david-maw/web-theme.git
Version with bug
10.0.50
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
No response
Affected platforms
Windows
Affected platform versions
Windows 11, Android 35+
Did you find any workaround?
Yes, before showing the web page explicitly set the WebView2 theme:
This code is in the reproduction code guarded with a compile-time WORKAROUND define.
Relevant log output