Android Load HTML And Javascript In Webview From Assets

Android Geeks, Welcome to Android Load HTML And Javascript In Webview From Assets tutorial.

Load HTML And Javascript In Webview Android example guide you to load HTML and JavaScript from local assets.

There will be situations where design of app can not be done with only xml file. You will need to implement html and css for better designing. Here, you will need to load html from asset.

We will also learn how can we integrate functions between android and JavaScript.

You will learn how to load HTML into Android WebView from String.

First, check the output of the tutorial then we will develop it.

Download Source Code for Load HTML And Javascript In Webview

[sociallocker]Download WebViewHtmlDemonuts [/sociallocker]

Step 1: Create a new project in Android Studio.

Make a new android studio project with empty activity.

Step 2: Making assets folder

Execute Rigth click on left menu bar->New Folder->Assets Folder as per below image

android webview html javascript

Creating JavaScript file

make new file and name it as load_JS_Demonuts.html

Copy below source code into it

put above file into assets folder.

We will fetch this file into Webview.

Step 3: Creating HTMLActivity

Make a new activity named HTMLActivity

put following code into activity_html.xml

Paste below source code into

In the above source code, we have store an HTML code into string variable. This string variable is loaded into the WebView with following code

Step 4: Creating JavaScriptActivity

Create a new activity named JavaScriptActivity

put below code into activity_java_script.xml

Paste below source code into

Step 5: Update MainActivity

Put below code in activity_main.xml

Update as per following

So that is all for Android WebView HTML JavaScript example.

If you have any questions or queries regarding this tutorial, then feel free to ask them in comment section.

You can also use comment section for your suggestions and reviews.

Thank you and keep sharing our tutorials.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

1 Response

  1. bhuvana says:


    I’m using AppcompatActivity for Rendering webview in my code.
    And also I used JavascriptInterface for autofill in webview .But It is working upto MarshMallow not from Nougat. I cannot resolve this issue Please help me.

Leave a Reply

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