Android加载html代码和文件
16lz
2021-01-26
我们都知道在Android上可以通过WebView加载网页,但是能否加载html的源码呢?答案是肯定的。一般条件下,我们可以在WebView上加载html的代码。
在WebView上加载html文件
WebView wView = (WebView)findViewById(R.id.wv1);WebSettings wSet = wView.getSettings(); wSet.setJavaScriptEnabled(true); // 打开本包内asset目录下的index.html文件wView.loadUrl("file:///android_asset/index.html"); // 打开本地sd卡内的index.html文件 wView.loadUrl("content://com.android.htmlfileprovider/sdcard/index.html");// 打开指定URL的html文件 wView.loadUrl("http://wap.baidu.com");
在WebView上加载html代码
String content = "hello baidu!
";webview.loadData(content, "text/html", "UTF-8"); // 加载定义的代码,并设定编码格式和字符集。
在WebView上添加css样式
String linkCss = "";String html = "" + linkCss + " " + content + "