admin管理员组文章数量:1390697
I’m facing an issue with the spellchecker (text suggestions) in Android WebView when using dark mode.
- In light theme, the spellchecker popup has a white background with black text, which is correct.
- In dark theme, the spellchecker background remains white, but the text is also white, making it unreadable.
Help me to fix this issue!!
In Dark Mode:
In Light Mode
I’m facing an issue with the spellchecker (text suggestions) in Android WebView when using dark mode.
- In light theme, the spellchecker popup has a white background with black text, which is correct.
- In dark theme, the spellchecker background remains white, but the text is also white, making it unreadable.
Help me to fix this issue!!
In Dark Mode:
In Light Mode
Share Improve this question edited Mar 17 at 10:04 Dinesh G asked Mar 14 at 10:05 Dinesh GDinesh G 929 bronze badges 2- Please provide more information to help us understand your issue. A screenshot and the version of the webview(or webkit) are required. – cmoaciopm Commented Mar 14 at 13:43
- I've updated with the screenshot of the issue @cmoaciopm – Dinesh G Commented Mar 17 at 10:05
1 Answer
Reset to default 01. Force Dark Mode on WebView
Ensure that your WebView is properly set up to support dark mode:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
webView.getSettings().setForceDark(WebSettings.FORCE_DARK_ON);
}
This should help WebView elements adapt to dark mode correctly.
2. Override WebView's Default Styling
Since the spellchecker popup is part of the WebView, you can try injecting custom CSS to override the default styles:
::selection {
background: #555; /* Adjust color */
color: white;
}
Use JavaScript to inject it dynamically:
webView.evaluateJavascript(
"document.addEventListener('DOMContentLoaded', function() {" +
" let style = document.createElement('style');" +
" style.innerHTML = '::selection { background: #555; color: white; }';" +
" document.head.appendChild(style);" +
"});",
null
);
3. Set the System Theme Properly
Ensure your app follows the system theme correctly:
<application
android:theme="@style/Theme.AppCompat.DayNight">
Then, in onCreate
:
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
本文标签: Android WebView Spellchecker Background Color Issue in Dark ModeStack Overflow
版权声明:本文标题:Android WebView Spellchecker Background Color Issue in Dark Mode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744662596a2618335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论