Web View Layout
Web View Layout
Mobile Development II
URL: www.KenyaInstituteofsoftwareengineering.com 13
Lecturer: Mr. John Kinyanjui
Tel: +254 202529389, +254 713 810 752, +254 732 609 809 email: [email protected]
Alternatives for Loading Content
You can also use loadData(). Here, you
supply the HTML for the WebView to
display. You might use this to:
◼ display a manual that was installed as a
file with your application package
◼ display snippets of HTML you retrieved
as part of other processing
◼ generate a whole user interface using
HTML, instead of using the Android
widget set
URL: www.KenyaInstituteofsoftwareengineering.com 16
Lecturer: Mr. John Kinyanjui
Tel: +254 202529389, +254 713 810 752, +254 732 609 809 email: [email protected]
URL: www.KenyaInstituteofsoftwareengineering.com Lecturer: Mr. John Kinyanjui
Tel: +254 202529389, +254 713 810 752, +254 732 609 809 email: [email protected]
Alternatively
If you have an HTML file located in the
assets folder of the project you can load
it into the WebView using the loadUrl()
method:
◼ WebView wv = (WebView)
findViewById(R.id.webview1);
◼ wv.loadUrl(“file:///android_asset/I
ndex.html”);
URL: www.KenyaInstituteofsoftwareengineering.com 18
Lecturer: Mr. John Kinyanjui
Tel: +254 202529389, +254 713 810 752, +254 732 609 809 email: [email protected]
URL: www.KenyaInstituteofsoftwareengineering.com 19
Lecturer: Mr. John Kinyanjui
Tel: +254 202529389, +254 713 810 752, +254 732 609 809 email: [email protected]
URL: www.KenyaInstituteofsoftwareengineering.com 20
Lecturer: Mr. John Kinyanjui
Tel: +254 202529389, +254 713 810 752, +254 732 609 809 email: [email protected]
Redirect
Sometimes when you load a page that
redirects you, WebView will cause your
application to launch the device’s
Browser application to load the desired
page.
To prevent this from happening, you
need to implement the WebViewClient
class and override the
shouldOverrideUrlLoading() method