android - 在 Android 应用程序中使用 jqMath

标签 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");

这段代码有什么问题?,

更新 好吧,我的问题已经解决,但我也将 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/

相关文章:

html - Flutter 中是否会有来自本地 Assets html 文件的离线 webview?

javascript - PhoneGap 如何在更改 window.location/document.location 后保持 Javascript 执行

javascript - ANDROID/WEBVIEW-- 未捕获的类型错误 : Object [object Object] has no method 'changeActivity' at file:

android - jqMath:如何在 Android 应用程序的 webview 上改进向量和上标/下标的显示

android - 计算 Android/iPhone 应用程序的功耗 (mW)

android - 在 Android 上使用 Esper 的 CEP?

android - AWS SNS Android GCM - InvalidPlatformToken

android - 使用 MediaCodec 解码原始 AAC 音频数据适用于 Android 4.4 但不适用于 4.3

android - 如何在 Android 中实际显示数学公式

javascript - Jqmath 产生奇怪的行为,不正确的渲染