如何在 webview 中加载一些 html 代码?
我想从一个有布局的地方发送一些HTML
代码,我想获取 代码并显示为页面。我的代码是:MainActivity
WebViewActivity
WebView
HTML
webview
HTML
HTML
<p><span style=\"font-size: 12pt;\">Sample text<\/span><\/p>\r\n<p><span style=\"font-size: 14pt; color: #00ffff;\">Sample text<\/span><\/p>\r\n<p><span style=\"font-size: 36pt; color: #99cc00;\">Sample text<\/span><\/p>\r\n<p><span style=\"font-size: 36pt; color: #ff0000;\">Sample text<\/span><\/p>\r\n<p> <\/p>
我WebViewActivity
的是:
String value;
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
value = getIntent().getStringExtra(MY_EXTRA);
Log.w(MY_EXTRA, "Data recieved is >> " + value);
setContentView(R.layout.webview);
this.getIntent().putExtra("loadUrlTimeoutValue", 60);
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadData(value, "text/html", null);
return true;
}
});
new getData().execute(null, null, null);
}
private class getData extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
webView.getSettings().setDomStorageEnabled(true);
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected Void doInBackground(Void... params) {
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(
false);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setRenderPriority(
WebSettings.RenderPriority.HIGH);
webView.getSettings().setSavePassword(false);
webView.setVerticalScrollBarEnabled(false);
webView.setHorizontalScrollBarEnabled(false);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setAppCacheMaxSize(200);
webView.getSettings().setDatabaseEnabled(true);
webView.clearCache(true);
// webView.clearHistory();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
webView.loadUrl(value);
}
}
现在我看不到我的HTML
代码的任何结果,并且我webview
没有显示任何东西。如何查看我的结果?任何身体!