Issue
I am using a WebView and am trying to load a HTML file into it which I have stored in my Resources/raw folder ( I cannot do assets because I am working with a ClassLibrary)
webView.LoadUrl("file:///android_res/raw/test.html");
What is happening is that the content of the file gets loaded in the WebView, the actual html code
This is what I see in my webview
<html>
<body>
<b>TEST THISSSSS</b>
</body>
</html>
When what I should be seeing is
TEST THISSSSS
Why is this happening ? What am I doing wrong ?
Solution
Load the raw resource via a stream (to string):
using (var stream = Resources.OpenRawResource(Resource.Raw.someHTMLBasedFile))
using (var streamReader = new StreamReader(stream))
{
webView.LoadDataWithBaseURL("file:///android_asset/", streamReader.ReadToEnd(), "text/html", "UTF-8", "");
}
Note: Since you are loading via a resource, you can provide res/raw-<qualifiers> folders if you need to internationalize via the device's locale.
Answered By - SushiHangover
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.