1

私は 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に変更しました。他の誰かが同じ問題を抱えている場合の参考のために言及します

4

3 に答える 3

6

次のように、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 フォルダーにある必要があることに注意してください。

于 2014-03-02T12:16:25.243 に答える
1

assets/js に js libs を配置したと仮定すると、assets フォルダー内の js lib の場所が src 宣言と一致しません。

于 2014-03-02T12:13:39.530 に答える