CHAPTER 13
Embedding the WebKit Browser
Other GUI toolkits let you use HTML for presenting information, from limited HTML renderers (e.g., Java/Swing, wxWidgets) to embedding Internet Explorer into .NET applications. Android is much the same, in that you can embed the built‑in Web browser as a widget in your own activities, for displaying HTML or full‑fledged browsing. The Android browser is based on WebKit, the same engine that powers Apple’s Safari Web browser.
The Android browser is sufficiently complex that it gets its own Java package (), though using the WebView widget itself can be simple or powerful, based upon your requirements.
A Browser, Writ Small
For simple stuff, WebView is not significantly different than any other widget in Android – pop it into a layout, tell it what URL to navigate to via Java code, and you’re done.
For example, is a simple layout with a WebView. You can find along with all the code samples for this chapter in the Source Code area at http://apress.com.
As with any other widget, you need to tell it how it should fill up the space in the layout (in this case, it fills all remaining space).
The Java code is equally simple:
Package
Import
Import
Import
Public class extends
Public onCreate
Super onCreate
SetContentView
Дата добавления: 2015-05-16; просмотров: 744;