Web view source code to use in android studio

If you want to load a web page inside an Android app and view its source code, you can use a WebView component in Android Studio. Here are the steps you can follow:

Open your Android Studio project and navigate to the XML layout file where you want to add the WebView component.

Add the following code to the XML file to create a WebView component:

Copy code

    android:layout_height="match_parent" />

This will create a full-screen WebView component.

In your Java code, you need to load the URL of the web page that you want to display in the WebView. Add the following code to your Java class:
Copy code
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true); //Enable JavaScript
This will load the web page of the URL "https://www.example.com" in the WebView component. You can replace this URL with the one you want to load.

To view the source code of the loaded web page, you can add the following code:
Copy code
webView.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView view, String url) {

This will add a WebViewClient to the WebView component and override its onPageFinished() method. When the web page finishes loading, the onPageFinished() method will be called and it will execute a JavaScript code to display the source code of the loaded web page in an alert dialog box.

Note: Keep in mind that some websites may not allow you to view their source code through a WebView.