How To Add/Create Local HTML File In Android Studio

We usually need HTML files for displaying your content in WebView. If you want to add any website page or want to create a local webpage for your app then it could be done using HTML files. Here we will show how to create local HTML file in Android Studio.


 How to add local HTML file  in android Studio

Step 1: For adding Local HTML page into your android studio project you must have Assets folder in it. Refer our Article :How to add Assets folder in Android Studio

Step 2: Once you have your assets folder  inside the project then right click on assets folder then NEW>FILE

assets new file in Android Studio

Step 3: Android Studio will show you a dialog box, it will ask you to give file name. Write any name as per your requirement.(for example: sample.html) and hit OK.

file name html in Android Studio

Step 4: Now you can see sample.html has created in the assets folder. Open it and edit as per your own requirements.

html in assets folder Android Studio

Step 5: Another option for adding HTML file: You can create a HTML page anywhere in your PC and then Copy it and paste it into assets folder.

Create HTML page in Android Studio

Important Note: When you want to load your HTML page in web view then use below code:

WebView web = new WebView();
web.loadUrl("file:///android_asset/sample.html");
make sure you cast the web view before using loadUrl() function :
web =(WebView)findViewById(R.id.webview);

Also Read:
1. WebView Tutorial
2. HTML in Android Tutorial With Example

DOWNLOAD THIS FREE eBook!

This free eBook will help you master the learning of Android App Development in Android Studio!

7 thoughts on “How To Add/Create Local HTML File In Android Studio”

  1. how to show admobe add in local html file on android studio.
    i have make an app which is based on html file now i can’t add admobe banner add inside html file…please sir tell me

  2. With this method, will it work with an entire website with javascript and css files? Or is it just a plain single HTML page that will work (iframes, pdf links, html5 videos).

    Mitchell

  3. Bonjour ici! J’ai un probleme en android.
    J’ai réussie à mettre Mon fichier Html (Accueil) dans Mon projet, Mais le fichier a des liens vers d’autre fichier j’arrive pas à faire. et pourtant j’ai les 3 fichier dans assets.

    Mercie de me répondre .