Android WebView Example

Here you will get android webview example.

Android WebView is a UI component used to open web url or show html data inside the activity.

Below I have given two examples, one is for opening a web url and another is for showing some html data in an activity.

Also Read: Android Load Image from URL (Internet) Example

 

Android WebView Example

Open Web URL

For opening a url we use loadURL() method of WebView class. By default the url is opened in android browser. As we have to open it inside the activity so we have to provide our own WebViewClient.

In this example the activity consists of three UI components namely EditText, Button and WebView. When user will enter url of a website in the edittext and click on button then the website will open in webview.

Create an android project with package name thecrazyprogrammer.androidexample and add following code in respective files.

activity_main.xml

 

MainActivity.java

 

Note: As we are fetching data from internet so we have to provide internet access permission. Just add following line in AndroidManifest.xml file.

 

Output

Android WebView Example 1

 

Show HTML Data

The loadData() method of WebView class is used to show html data. It can be done in following way.

Create an android project with package name thecrazyprogrammer.androidexample and add following code in respective files.

activity_main.xml

 

MainActivity.java

 

Output

Android WebView Example 2

Comment below if you found anything incorrect or have doubts related to above android webview example.

Leave a Reply

Your email address will not be published. Required fields are marked *