Ara*_*ash 1 android webview jqmath
我是Android编程的新手,我想让我们jqMath在WebView中显示一些数学公式.
这是我的代码:
WebView webView = (WebView)findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
String js = "<html><head>"
+ "<link rel='stylesheet' href='jqmath-0.4.0.css'>"
+ "<script src='jquery-1.4.3.min.js'></script>"
+ "<script src='jqmath-etc-0.4.0.min.js'></script>"
+ "</head><body>"
+ "<script>var s = '$ax^2+bx+c=0$ with $a?0$';M.parseMath(s);document.write(s);</script></body>";
webView.loadData(js, "text/html", "UTF-8");
Run Code Online (Sandbox Code Playgroud)
这段代码有什么问题?
更新 好我的问题已经解决了,但我也将loadData函数更改为loadDataWithBaseURL我提到的仅供参考,如果其他人有同样的问题
您需要为css,js文件正确指定路径,如下所示:
WebView webView = (WebView)findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
String path="file:///android_asset/";
String js = "<html><head>"
+ "<link rel='stylesheet' href='"+path+"jqmath-0.4.0.css'>"
+ "<script src='"+path+"jquery-1.4.3.min.js'></script>"
+ "<script src='"+path+"jqmath-etc-0.4.0.min.js'></script>"
+ "</head><body>"
+ "<script>var s = '$ax^2+bx+c=0$ with $a?0$';M.parseMath(s);document.write(s);</script></body>";
webView.loadData(js, "text/html", "UTF-8");
Run Code Online (Sandbox Code Playgroud)
请注意,文件应位于assets文件夹中.
归档时间: |
|
查看次数: |
3022 次 |
最近记录: |