Android Tutorial

(avery) #1

By : Ketan Bhimani


382 

The following is an example of how to use WebViewClient to handle
the onPageFinished() method to draw the title of the page on the
screen:

WebViewClient webClient = new WebViewClient() {
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String title = wv.getTitle();
pageTitle.setText(title);
}};
wv.setWebViewClient(webClient);


When the page finishes loading, as indicated by the call to
onPageFinished(), a call to the getTitle() method of the WebView
object retrieves the title for use. The result of this call is shown in
Figure.

WebView control with microbrowser features such as title
display.

Adding Browser Chrome with WebChromeClient

You can use the WebChromeClient class in
a similar way to the WebViewClient.
However, WebChromeClient is specialized
for the sorts of items that will be drawn
outside the region in which the web
content is drawn, typically known
as browser chrome. The
WebChromeClient class also includes
callbacks for certain JavaScript calls, such
as onJsBeforeUnload(), to confirm
navigation away from a page. A valid
WebChromeClient object can be tied to a
WebView using the set Web Chrome
Free download pdf