Simple loading of Static and Dynamic URL on Android Web View

0
255

In  previous tutorial we have learned on how to use HTML string and load it inside the Web View.Now we’re going to work on how to load external Links or URL to be viewed on Web View in Native android app.

Let’s Start by adding a Web View on the Layout, then add an EditText above and a Button beside it.This may look like a Browser because we are going to load URL using the EditText.

Before we proceed, first we need to have a WebViewController class.

Create new class >> WebViewController.java and add the codes below.

Next is the same as the previous tutorial, we need to declare all elements used in order to use this in your activity file.

After declaring all elements,what we need to do is to Load URL inside Web View statically and it will serve as the Home Page of our browser.

Then call the function() on the onLoad/onCreate of the activity.

Before testing the application we must use this permission in order to access Internet.

Put this inside your Manifest.xml file.

By testing the application, it must lead you directly to this site as our home page or the default page.

After setting our home page, we need to work on how to load URL using the EditText above.

We need to fetch text from the EditText above then convert it to String and load it as an URL for our Web View just use the codes below.

Next is to call this function() on the onClick event of the Button.

Thus giving you this result.

Download “WebView_url.rar” WebView_url.rar – Downloaded 64 times – 1 MB