34

While using WebView, we usually put a URL for it:

WebView.loadUrl(myURL);

but it is possible to put HTML code directly?? So that it will be in a logic that:

WebView.loadContent ( <html><head><script></script></head><body>....</body></html> );

Thanks.

3 Answers 3

58

Check out this: http://developer.android.com/reference/android/webkit/WebView.html

 // OR, you can also load from an HTML string:
 String summary = "<html><body>You scored <b>192</b> points.</body></html>";
 webview.loadData(summary, "text/html", null);
Sign up to request clarification or add additional context in comments.

Comments

12
 String yourhtmlpage = "<html><body>You scored <b>hello world</b> points.</body></html>";
 webview.loadDataWithBaseURL(null, yourhtmlpage, "text/html", "UTF-8", null);

2 Comments

What is the baseURL part for?
> Loads the given data into this WebView, using baseUrl as the base URL for the content. The base URL is used both to resolve relative URLs and when applying JavaScript's same origin policy. The historyUrl is used for the history entry.
7

Try this code. It works for me.

WebSettings settings = mDesc.getSettings();
settings.setDefaultTextEncodingName("utf-8");
mDesc.loadData(mDescText, "text/html; charset=utf-8",null);

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.