2013-06-29 6 views
20

これは私の主な活動のAndroidのWebView、3.xの

package com.example.mathjax_issues; 

import android.os.Bundle; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.util.Log; 
import android.view.Menu; 
import android.webkit.WebResourceResponse; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class MainActivity extends Activity { 


    private WebView webView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     webView=(WebView)findViewById(R.id.webView1); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.setWebViewClient(new MyWebViewClient()); 
     webView.loadUrl("file:///android_asset/MathJax/test/sample-asciimath.html"); 
//  String html="<!DOCTYPE html> <html> <head> <title>MathJax AsciiMath Test Page</title> <!-- Copyright (c) 2012-2013 The MathJax Consortium --> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /> <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" /> <script type=\"text/javascript\" src=\"file:///android_asset/MathJax/MathJax.js?config=AM_HTMLorMML-full\"></script> </head> <body> <p> When `a != 0`, there are two solutions to `ax^2 + bx + c = 0` and they are </p> <p style=\"text-align:center\"> `x = (-b +- sqrt(b^2-4ac))/(2a) .` </p> </body> </html> "; 
//  Log.e("html",html); 
//  webView.loadDataWithBaseURL("file:///android_asset/MathJax", html, "text/html","utf-8", ""); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 


    private class MyWebViewClient extends WebViewClient 
    { 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      // TODO Auto-generated method stub 
      super.onPageFinished(view, url); 
     } 

     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon) { 
      // TODO Auto-generated method stub 
      super.onPageStarted(view, url, favicon); 
     } 




    } 



} 

この私のサンプルasciimath.html以下

<!DOCTYPE html> 
<html> 
<head> 
<title>MathJax AsciiMath Test Page</title> 
<!-- Copyright (c) 2012-2013 The MathJax Consortium --> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

<script type="text/javascript" src="../MathJax.js?config=AM_HTMLorMML-full"></script> 

</head> 
<body> 

<p> 
When `a != 0`, there are two solutions to `ax^2 + bx + c = 0` and they are 
</p> 
<p style="text-align:center"> 
`x = (-b +- sqrt(b^2-4ac))/(2a) .` 
</p> 

</body> 
</html> 

での画像であります私のプロジェクト

enter image description here

2.3.3,2.2,4.1.2,4.2.2緯度にこのコードをコンパイルしますエストバージョン

私はソース

enter image description here

が、私は私が3.0,3.1と4.0.3,4.0.4アンドロイドのバージョン

で同じソースをコンパイルからの正しい出力を得ますplsは私を助けて、この

enter image description here

友達のような間違った出力を取得...私はすることができませんこのエラーを解決する...私は...あなたたちは私に私が資産に..ローカル事前に

感謝をmathjaxを格納しています

いくつかのアイデアを与えるjavascriptのproblem.Hopeがあるかもしれないと思う

+0

は[この記事]で説明されたあなたの問題を解決する、[1] [1]:http://stackoverflow.com/questions/17029780/display-good-looking-math-formula-in-android?answertab=active#tab-top –

+0

すべての回答が私のために働いていません –

+0

私は何も仕事の友人を除いてすべてを試みました.. –

答えて

2

一部の人々はすでにこの問題を抱えていました(実際には...それらの多く...)。 https://stackoverflow.com/a/7197748/1387484

ドキュメントが完全にロードした後、あなたは、手動でWebViewClientであなたのJavaScript呼び出しを注入する必要が表示されます。

つのポスト(とも1つの答えは)私の注目を浴びました。私はそれ以上の説明はありませんが、おそらくあなたはこの方法を試すことができます!

+0

働かない男 –

6

私にも同様の問題がありました。私がしたことは、すべての.jsファイルをhtmlがある場所と同じディレクトリにコピーして、次のように追加したことです。

<script type="text/javascript" src="MathJax.js"></script> 

私はちょっと馬鹿だとは思いますが、うまくいきました。

それは、仕事htmlファイル自体に.jsファイルをコピーして、ヘッダのようにそれをしようとしていない場合:

<script type="text/javascript"> 
copy the whole MathJax.js and paste it here 
</script> 
+0

私の友人これもあまり働かない –

+0

あなたは答えを見つけましたか?私があなたのjsファイルがロードされていないと言うことができます。あなたはHTMLファイル自体の内部にjavascript関数を書こうとしましたか?ボディのonloadにalert()を挿入して、プロセスを少し保持して、urのJSファイルをロードする時間を与えてください。私に教えてください.. – Navin

+0

ya私は書いたが、何もロードしない –

2

問題はこのアンドロイドのバグに関連しているようです。あなたがURLパラメータでファイルを参照している場合、HTTP 404(ファイルが見つかりません)が発生します。あなたの場合、 "MathJax.js?config = AM_HTMLorMML-full"というスクリプトは見つからず、ロードされません。

Overcoming Honeycomb and Ice Cream Sandwich’s Broken WebView URLs

<!-- hack for honeycomb & ICS -- first script tag will not load but it's --> 
<!-- needed for proper MathJax initialisation - clean solution would be to --> 
<!-- pass the init data "AM_HTMLorMML-full" in some other way to MathJax --> 
<script type="text/javascript" src="../MathJax.js?config=AM_HTMLorMML-full"></script> 
<script type="text/javascript" src="../MathJax.js"></script> 
2

スクリプトはHTMLファイルに比べて、外のフォルダに見つからないときに動作します。

MathJaxフォルダーからhtmlファイルを取り出し、以下のようにhtmlファイルの行を変更すると動作します。

<script type="text/javascript" src="./MathJax/MathJax.js?config=AM_HTMLorMML-full"></script>

そしてもちろんのwebView.loadUrl("file:///android_asset/sample-asciimath.html");

0

にjavaファイルを変更するには、コンフィギュレーション(AM_HTMLorMML-full.js)に設定する必要があるため問題があるHTMLファイル内mathjaxのためには、(コードをコピー)ファイルに、あなたは以下のコードのように、MathJax.jsファイルの完全なパスをepecifyする必要があります。

<!DOCTYPE html> 
    <html> 
     <head> 
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
      <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
      <script type="text/javascript" src="../MathJax/MathJax.js"> 
       MathJax.Hub.Config({ 
        config: ["MMLorHTML.js"], 
        extensions: ["asciimath2jax.js","MathEvents.js","MathZoom.js","MathMenu.js","toMathML.js"], 
    jax: ["input/AsciiMath","output/HTML-CSS","output/NativeMML"] 
       }); 
       MathJax.Ajax.loadComplete("[MathJax]/config/AM_HTMLorMML-full.js"); 
      </script> 
    </head> 
    <body> 
     <p>`\sqrt{2x + 1}`</p> 
    </body> 
    </html>