Technical

How to add/create local HTML file in android studio for App

How to add/create local HTML file in android studio for App. We can present the data in our Android with the help of HTML, we create an HTML file in the asset directory of our application or we can keep our HTML files by creating a new directory in the asset directory.

How to add/create local HTML file in android studio for App
How to add/create a local HTML file in android studio for App

Usually, we need HTML files to display our content in WebView. If we want to add a website page to our mobile or create a local webpage for our app, this can be done using HTML files. Here we will explain how to create a local HTML file in Android Studio. And in which folder these files are stored from where we can easily access these files. You will need to generate the assets folder in your Android Studio to hold HTML files.

How to create assets folder in android studio

When creating an Android application we need some extra files such as text, HTML, etc. In Android Studio we need the Assets folder to keep these files. So that we have easy access to these files.

App>new>folder>Assets Folder

To create an assets folder, follow these steps.

How to create assets folder in android studio
How to create assets folder in android studio

 

  • Right-click on your project name in Android Studio.
  • Click on the new.
  • Click on the folder icon.
  • At the top, you will see the assets folder name, click on it.
  • Your assets folder generation is complete.

Steps to add local HTML files in Android Studio

After the asset folder generation, you have to follow these steps. You can add HTML files to Android Studio by following these steps.

Steps to add local HTML files in Android Studio
Steps to add local HTML files in Android Studio

 

Step 1: Right-click on the assets folder.

Step 2: Click on New

Step 3: Click on a file to Create an HTML file in android studio.

Step 4: Give the name of your HTML file and press Enter.

Give the name of your HTML file
Give the name of your HTML file

The file has been created in your Android Studio. You will see something like this in the asset folder.

file has been created in your Android Studio
file has been created in your Android Studio

Your HTML file creation test is complete. You can create as many files as you want in the Assets folder. use the code below to load your HTML page into the web view:

Java code for Web View:

//You have to create web view to run html in your application.
webView =(WebView)findViewById(R.id.mywebview);
WebView web = new WebView();
webView.loadUrl("file:///assets/sample.html");

 

Leave a Reply

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