Skip to content

Commit

Permalink
add dark mode to topbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Avinash-Codes committed Dec 23, 2024
1 parent f588e4f commit 1e1fe95
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ class WebViewActivity : AppCompatActivity() {
when (nightModeFlags) {
android.content.res.Configuration.UI_MODE_NIGHT_YES -> {
webSettings.forceDark = WebSettings.FORCE_DARK_ON
activityWebViewBinding.contentWebView.webTitle.setTextColor(resources.getColor(android.R.color.white))
activityWebViewBinding.contentWebView.webSource.setTextColor(resources.getColor(android.R.color.white))
activityWebViewBinding.contentWebView.contentWebView.setBackgroundColor(resources.getColor(android.R.color.black))
}
android.content.res.Configuration.UI_MODE_NIGHT_NO -> {
webSettings.forceDark = WebSettings.FORCE_DARK_OFF

activityWebViewBinding.contentWebView.webTitle.setTextColor(resources.getColor(android.R.color.black))
activityWebViewBinding.contentWebView.webSource.setTextColor(resources.getColor(android.R.color.black))
}
}
}
Expand All @@ -72,10 +78,8 @@ class WebViewActivity : AppCompatActivity() {
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)

// Detect if dark mode
val nightModeFlags = resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK
if (nightModeFlags == android.content.res.Configuration.UI_MODE_NIGHT_YES) {
// Enable dark mode
view.evaluateJavascript(
"""
(function() {
Expand All @@ -93,7 +97,6 @@ class WebViewActivity : AppCompatActivity() {
null
)
} else {
// Revert to light mode
view.evaluateJavascript(
"""
(function() {
Expand All @@ -116,7 +119,6 @@ class WebViewActivity : AppCompatActivity() {
}
}


private fun clearCookie() {
val cookieManager = CookieManager.getInstance()
cookieManager.removeAllCookies(null)
Expand Down

0 comments on commit 1e1fe95

Please sign in to comment.