0% found this document useful (0 votes)
3 views1 page

How To

The document provides source code for implementing a WebView in an Android application. It includes instructions for loading a URL, enabling JavaScript, and handling page navigation with a custom WebViewClient. Additionally, it demonstrates how to manage the back button functionality to navigate through the web pages loaded in the WebView.

Uploaded by

spacestoryme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

How To

The document provides source code for implementing a WebView in an Android application. It includes instructions for loading a URL, enabling JavaScript, and handling page navigation with a custom WebViewClient. Additionally, it demonstrates how to manage the back button functionality to navigate through the web pages loaded in the WebView.

Uploaded by

spacestoryme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

https://www.youtube.com/watch?

v=mLsLwqpDoE4

Source code to copy and paste:

android:id="@+id/webview"

import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

Source Code from 04:03 (Replace example.com with own URL)


===================================================

mywebView=(WebView) findViewById(R.id.webview);
mywebView.setWebViewClient(new WebViewClient());
mywebView.loadUrl("https://www.example.com/");
WebSettings webSettings=mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);

Source Code 2 from 04:30


=====================

public class mywebClient extends WebViewClient {


@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view,url,favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public void onBackPressed() {
if (mywebView.canGoBack()) {
mywebView.goBack();
} else {
super.onBackPressed();
}
}

You might also like