最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Android WebView Theme Issue: Forced Light or Dark Mode lead Mixed UI Components After WebView Closure - Stack Overflow

programmeradmin3浏览0评论

I am experiencing an issue in my Android app related to using WebView in a fragment while forcing a theme mode opposite to the system's current mode. When the system is in dark mode, I force light mode in my app, and after opening a WebView, the UI components mix between light and dark modes when the WebView is closed. Specifically, I am using setWebViewClient to load a URL, and I've tried controlling WebView settings with forceDark = WebSettings.FORCE_DARK_OFF, but the problem persists.

Steps to Reproduce: 1- The system is in dark mode. 2- I force light mode using the app (via AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)). 3- Open a WebView (with a custom URL) inside a fragment. 4- After the WebView is closed, the app UI components have mixed resources—some appear in dark mode and others in light mode.

What I’ve Tried: 1- Using forceDark = WebSettings.FORCE_DARK_OFF in WebView settings. 2- Calling invalidate() on the decorView. 3= Calling recreate() on the activity, but that resets the state of the app, which I don’t want. 4- Forcing light mode using AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO).

Is there a way to force the UI to stay in light mode (or the chosen mode) after interacting with WebView, without causing mixed resources? What is the best approach to ensure the app doesn’t reset its state while handling theme changes correctly?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论