Paste a piece of HTML or Javascript script inside webview in android

I have a small piece of Javascript and HTML code for a table containing statistics that I want to embed in WebView in my Android application. How can i do this. Can anyone suggest me an example and sample code. Please, help

+4
source share
3 answers

you can create an html page and put the resource folder and upload the html page to webview.

using this code:

webView.loadUrl("file:///android_asset/index.html"); 
+5
source
  WebView webView; String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body style='margin:0; pading:0; background-color: black;'>"; String htmlCode = " <embed style='width:100%; height:100%' src='http://www.platipus.nl/flvplayer/download/1.0/FLVPlayer.swf?fullscreen=true&video=http://www.platipus.nl/flvplayer/download/pl-600.flv&autoplay=true' " + " autoplay='true' " + " quality='high' bgcolor='#000000' " + " name='VideoPlayer' align='middle'" + // width='640' height='480' " allowScriptAccess='*' allowFullScreen='true'" + " type='application/x-shockwave-flash' " + " pluginspage='http://www.macromedia.com/go/getflashplayer' />" + ""; String htmlPost = "</body></html>"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webView = (WebView)findViewById(R.id.webview); webView.loadDataWithBaseURL("null", htmlPre+htmlCode+htmlPost, "text/html", "UTF-8", null); } 

above is an example of using html code in webView.

+4
source

You can copy the HTML into assets and then display it in a WebView as follows:

 webView.loadUrl("file:///android_asset/index.html"); 

where WebView is your WebView object and index.html is your original HTML file.

+1
source

Source: https://habr.com/ru/post/1416303/


All Articles