WebView in Android :

WebView is a view that display web pages or website inside your application. you can also use hypertext mark-up language(HTML) string and can show it inside your application using WebViewWebView makes turns your application to a web application.

WebView in Android 4.4

Android 4.4 (API level 19) introduces a replacement version of WebView that’s based on chromium. this modification upgrades WebView performance and standards support for HTML5, CSS3, and JavaScript to match the newest web browsers. Any apps using WebView will inherit these upgrades once running on android 4.4 and higher.

android webview kitkat example

Sometimes your android application needs to load content from the web, like pictures or websites. This example shows you how to implement a web browser in your application and use it to load content from the web, as well as content stored locally in your application.

In this Example we use webview in two formats :

1.  Display site directly form internet into Webview

2.  Load site from Asset folder

This example describes additional changes to WebView that you simply should be aware of if you set your TargetSdkVersion to “19” or higher.

 1.  Display site directly form internet into Webview :

In this example , you will create two layout, first layout with button which navigate another layout. second page have webview component and Show Website.

Solution Stuff :

1. Open “res/layout/webviewex.xml” file and put this xml code it into file:

File : res/layout/webviewex.xml

The WebView component defines a web browser in your Android activity. You can also use it to load content from the web or resources stored locally in your application.

2. Open “LoadWeb.java” file and add following JAVA code.

File : src/package-name/LoadWeb.java

Note: To use the WebView in your application, you need to remember to add the INTERNET permission to your AndroidManifest.xml file:

3. Open “activity_main.xml” file and add following JAVA code.

File : src/package-name/activity_main.xml

Add Buttons navigate to WebView layout.

Screenshot :

android webview kikat 4.4 example4. Open “MainAcitvity.java” file and add following JAVA code.

File : src/package-name/MainActivity.java

Note:  you need to remember to add the LoadWeb activity to your AndroidManifest.xml file:

5. AndroidManifest.xml file code.

Output of  WebView  in emulator :

android webview example kitkat 4.2


 2.  Load site from Asset folder :

If you want to load content from a file, perhaps set in the assets folder of your project (see Figure), you’ll also load the WebView with the content stored in the file.

android webview example

1. Assume that the index.html file contains the following:

File : assets/index.html

2. Open “LoadingAssetsFolder.java” file and add following JAVA code.

File : src/package-name/LoadingAssetsFolder.java

The following Activity loads the WebView using the content of index.html:

 Output shows the WebView displaying the content and image of the file.

android webview example kitkat 4.4

Download Android Web Pages (webview) example in KitKat 4.4 Source code :

  1. running Android 4.4.2. Web pages do not download. Instructions above is far too complicated for the average Joe like me. How do I download web pages on Android 4.4.2?
    Ready to buy iphone and get rid of Android out of frustration. Why can’t I just download a simple web page link? Always… webpage not available try later or the web page just does not come up on the screen. or refresh this web page… again nothing comes up. next mobile is iOS guaranteed.

Leave a Reply