From 27d9108a001ed80eccda1ab861c216a072376863 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Sat, 9 Dec 2023 12:50:09 -0300 Subject: [PATCH] fix: make Anki pages bg color follow the app theme --- .../java/com/ichi2/anki/pages/PageWebViewClient.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/pages/PageWebViewClient.kt b/AnkiDroid/src/main/java/com/ichi2/anki/pages/PageWebViewClient.kt index 681d31581636..5c9b8403a9a0 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/pages/PageWebViewClient.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/pages/PageWebViewClient.kt @@ -18,6 +18,9 @@ package com.ichi2.anki.pages import android.webkit.WebView import android.webkit.WebViewClient import androidx.core.view.isVisible +import com.google.android.material.color.MaterialColors +import com.ichi2.anki.R +import com.ichi2.utils.toRGBHex /** * Base WebViewClient to be used on [PageFragment] @@ -25,8 +28,13 @@ import androidx.core.view.isVisible open class PageWebViewClient : WebViewClient() { override fun onPageFinished(view: WebView?, url: String?) { super.onPageFinished(view, url) - /** [PageFragment.webView] is invisible by default to avoid flashes while - * the page is loaded, and can be made visible again after it finishes loading */ - view?.isVisible = true + view?.let { webView -> + val bgColor = MaterialColors.getColor(webView, android.R.attr.colorBackground).toRGBHex() + webView.evaluateJavascript("document.body.style.backgroundColor = '$bgColor';") {} + + /** [PageFragment.webView] is invisible by default to avoid flashes while + * the page is loaded, and can be made visible again after it finishes loading */ + view.isVisible = true + } } }