Skip to content

Conversation

@sushantsikka
Copy link

No description provided.

@snippet-bot
Copy link

snippet-bot bot commented Oct 23, 2025

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@sushantsikka sushantsikka requested review from cartland and riggaroo and removed request for cartland and riggaroo October 23, 2025 15:05
@sushantsikka sushantsikka requested a review from cartland October 24, 2025 17:34
@sushantsikka
Copy link
Author

@cartland could you please check if these file locations make sense?

Copy link
Contributor

@cartland cartland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time someone merges a pull request, you will need to rebase on top of the main branch. Sometimes this is easy, but if there are conflicts you will need to resolve them.

Screenshot 2025-10-27 at 9 20 03 AM

@@ -0,0 +1,37 @@
package com.example.webviewdarkmode
Copy link
Contributor

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)
}
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants