Rendering Web Pages Inside Android Activities

0

While you create Android activities, you supply the activity view content
either through XML or dynamically through the code. But, sometimes the content
in the view, specifically the static content (content that does not change with
different runs) may be a web page; e.g. "Help" Activity or "Terms and
Conditions" Activity of your application.

These contents can be done as web pages, and that will help you in changing
the content without affecting the client side application binary. However,
sometimes you need to open these pages inside your application as an activity, and
not through the web-browser, e.g. open "Terms and Conditions" web page for the
user to accept or reject through button actions.

Android has a great widget supplying this capability – the WebView
component. It accepts either plain text as you would use in the TextView
component or a URL to a web page to render inside your activity.

The following example shows a layout of a sample activity containing WebView
to show the eSpace site homepage:

You
first create the layout XML file that contains your component as follows:

And then supply the URL to WebView through your activity "onCreate" method:

Now, the given URL is rendered inside the WebView widget and you can deal
with the opened web page with all functionality available from the Android
web-kit (scroll, zoom in, zoom out, etc).

Post a Comment

eSpace podcast Prodcast

RSS iTunes