Android WebView example

In this post, we are going to see Android webview example.
Android WebView is a android UI widget which is used to open any web url or load html data. It is used to show web page in android activity. In simple words, Andorid WebView is a View that displays web pages.
Example :
Lets say You are creating an android app and you have some user agreement or some web pages hosted online, you can just render it using Android WebView.
There are two methods which we generally use to open web url or load html data.

  • loadUrl
  • loadData
I am going to demonstrate about loadUrl in this post and loadData in next post.

Source code:

Step 1 :Creating Project

Create an android application project named “WebViewExampleApp”.

Step 2 : Creating Layout

Change res ->layout -> activity_main.xml as below:

Step 3 : Creating MainActivity

Change src/main/packageName/MainActivity.java as below:
We are getting WebView reference from layout file and then using WebView’s loadUrl method to load the URL

Step 4: Add internet permission in AndroidManifest.xml

Copy following code:

Put it in AndroidManifest.xml

Done, we have added internet permission to AndroidManifest.xml. Your application must be able to access internet now.

Step 5 : Running the app

When you run the app, you will get below screen:

Android WebView Example

Was this post helpful?

Leave a Reply

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