我是 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");
这段代码有什么问题?,
更新 好吧,我的问题已经解决,但我也将 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");
请注意,文件应位于 Assets 文件夹中。
关于android - 在 Android 应用程序中使用 jqMath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127355/