Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directly put html code in a WebView (Android)

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.

like image 651
Kit Ng Avatar asked Dec 22 '12 11:12

Kit Ng


People also ask

How do I load HTML code into WebView?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.

Which method is used to load HTML content in WebView?

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.

Is it possible to get data from HTML forms into Android while WebView?

Yes you can, you can use javascript to get webpage content. Then use the webview jsInterface to return the content to you java code.


1 Answers

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); 
like image 138
Terel Avatar answered Sep 19 '22 05:09

Terel