Simple Android WebView code for accessing a website within app

Here in this post I am going give you simple android WebView code to open a website through an android app. The WebView class is a built-in extension of Android’s View class that allows you to display web pages as a part of your activity layout.

If an android developer wants to add browser functionality for browsing a web page or website to an application, the developer can include the WebView library and create an instance of a WebView class. This is not a fully developed web browser, all that WebView do is displaying the web page in the layout. Thus you can render web pages and even also JavaScript of the web page easily.

How to add WebView in android the layout?

To add a WebView to your Application, you need to include the <WebView> element in your activity layout XML. Below is an example code:

      android:layout_height="match_parent" />

Then use loadUrl() to load a web page in your application:

WebView myWebView = (WebView) findViewById(;

To load the web page in your web view your application must request the INTERNET permission from the manifest file.

That’s all you need to do for a basic WebView application which loads a web page in the app.

To load the JavaScript from the web page and let it work you need to add this code:

WebSettings webSettings = mWebView.getSettings();

Now you will see that all the link from the app is opening via the default browser of your Android device. However, it needs to open in the app through WebView. To do this you need to add this code:

mWebView.setWebViewClient(new WebViewClient());


Android WebView code with basic features:

I have already created a complete WebView app with these features given below:

  1. Showing a progress bar while loading the web page first time after starting the app.
  2. Check internet connection if it is available and display no internet connection when there are no internet connection is available.

You can buy the complete source code from here only for $3 –

the source code is mainly for the newbies android developers. You can improve the source code and implement more features.

Leave a Reply

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