How to put and show an html file in my android studio project?

3

I would like you to help me with this topic, because I have a folder with html content, in the folder is the index.html, the css folder, the images folder and everything related to the page; I want to show this page in an activity through a WebView, I do not have an example to show but I saw a project that had this in an Asset folder; Can someone help me please?

    
asked by Ivan Alfredo 29.06.2017 в 16:39
source

2 answers

5

Definitely you have to save your html or its resources first inside the folder assets.

Create the folder, since by default it does not exist:

When creating the folder place your html and resources inside, it is important that you define the references within your html by calling them using file:///android_asset , to load the html in a WebView from assets is done this way:

 myWebView.loadUrl("file:///android_asset/myfile.html");
    
answered by 01.07.2017 / 08:35
source
4

To load an html from assets:

WebView wv = (WebView) findViewById(R.id.webView);  
wv.loadUrl("file:///android_asset/index.html");

Remember that the index.html must make references to the other files (css, js, etc) through relative routes.

Greetings.

    
answered by 29.06.2017 в 18:20