1

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 ?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.