-
Couldn't load subscription status.
- Fork 285
Add sample for WebView force dark mode #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
|
@cartland could you please check if these file locations make sense? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| @@ -0,0 +1,37 @@ | |||
| package com.example.webviewdarkmode | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package should match the directory structure after /java. In this case, it should be com.example.snippets.jetpackwebkit
| // To enable a modern feature, you pass that instance to a Jetpack Webkit helper. | ||
| if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { | ||
| WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet is supposed to match the snippet here:
https://developer.android.com/develop/ui/views/layout/webapps/jetpack-webkit-overview
// You still get your WebView instance the standard way.
val webView: WebView = findViewById(R.id.my_webview)
// To enable a modern feature, you pass that instance to a Jetpack Webkit helper.
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON)
}
This snippet also adds additional code:
// This is necessary to keep navigation inside your WebView
webView.webViewClient = WebViewClient()
// Enable JavaScript
webView.settings.javaScriptEnabled = true
Is this additional code expected and required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't harm to retain these lines of code, so prefer to retain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not add a new module. We should edit the build file for the existing misc module.
https://github.com/android/snippets/blob/main/misc/build.gradle.kts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not add a new Gradle version catalog. We should edit the existing version catalog.
https://github.com/android/snippets/blob/main/gradle/libs.versions.toml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this file appears to be a layout but the contents is an Android manifest file.
The code snippet uses R.layout.activity_main so you need the manifest file to match, activity_main.xml.
https://developer.android.com/guide/topics/resources/layout-resource
Then the contents will need to be updated to be a layout. For the snippet to compile, it can be a very simple layout file.
|
|
||
| // You still get your WebView instance the standard way. | ||
| // [START android_views_notifications_build_basic] | ||
| val webView: WebView = findViewById(R.id.my_webview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original snippet has the imports. To include the snippets in the region tag, it would be easiest to include them as comments here. Region tags around the real imports above would not be stable because our style formatting tools in Android Studio and Spotless will reorder imports and comments, which would break region tags if you try to use them up there.
// import android.webkit.WebView
// import androidx.webkit.WebSettingsCompat
// import androidx.webkit.WebViewFeature

No description provided.