Displaying Static HTML Content in Android WebView
Basic WebView Implementation
Loading a live web page from the internet into WebView object is straightforward.
The simplest way is to create a WebView object and load URL into the object:
|
|
Loading Custom HTML Content
Simple HTML String
For a simple static page you can create a HTML document in a string variable and load it into WebView object:
|
|
Complex HTML with CSS
For more complex HTML pages with CSS blocks, you need to have a HTML file and store it in your project asset folder.
You need to use loadDataWithBaseURL()
method instead to provide WebView with asset folder as base URL (where data
is content of HTML file):
|
|
Reading HTML from Assets
You can read content of HTML file from asset folder and save it into a String variable (data) and pass it to loadDataWithBaseURL method.
Below method is just one way of reading a file content into a variable:
|
|