繁体   English   中英

在Android应用程序中使用jqMath

[英]Using jqMath in Android application

我是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");

该代码有什么问题?,

UPDATE很好地解决了我的问题,但是我也将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");

请注意,这些文件应位于资产文件夹中。

假设您将js库放置在assets / js中,则js库在assets文件夹中的位置与您的src声明不匹配

在指定了Khalid所说的路径之后,以下对我有用

webView.loadDataWithBaseURL( "file:///android_asset/" ,js,  "text/html",  "UTF-8", null);

而不是webView.loadData方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM