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 + } } }