Tuesday, August 14, 2012

Load local HTML from assets in Android

We can load local HTML (under /assets folder) in WebView. 

Load local HTML from /assets

Modify from the former post Handle the Back button in WebView, to back in history

Create our local HTML, /assets/myweb.html. 
<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width; user-scalable=0;" />

<title>Android Coding</title>
</head>
<body>

<h1>Hello!</h1>
It's a local html in /assets.<br/>
Visit <a href="http://android-coding.blogspot.com/?m=1">Android Coding</a>

</body>

</html>


Load the local HTML in Java code: 

 final String DEFAULT_URL = "file:///android_asset/myweb.html";



 webView.loadUrl(DEFAULT_URL);

No comments:

Post a Comment