Skip to content

Commit

Permalink
fix: make Anki pages bg color follow the app theme
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Dec 9, 2023
1 parent 8e6e147 commit 27d9108
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/PageWebViewClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ 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]
*/
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
}
}
}

0 comments on commit 27d9108

Please sign in to comment.