这是我的主要活动
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
This my sample-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>
下面是我的项目的形象
below is the image of my project
在2.3.3,2.2,4.1.2,4.2.2最新版本编译此code时
when compiling this code in 2.3.3,2.2,4.1.2,4.2.2 latest versions
我得到从源头上正确的输出
I get the correct output from the source
但是当我在3.0,3.1和4.0.3,4.0.4 Android版本编译相同的源
but when i compiled the same source in 3.0,3.1 and 4.0.3,4.0.4 android version
我收到了错误的输出像这样
I am getting the wrong output like this
朋友们请帮我...我无法来解决这个错误......我觉得有可能是一个JavaScript problem.Hope你们给我一些想法
Friends pls help me ... I am unable to solve this error ... I think there may be a javascript problem.Hope you guys give me some idea
我存储mathjax地方。在资产
I am storing the mathjax locally .. in assets
在此先感谢...
我也有类似的问题。我所做的是我复制到同一目录中,其中HTML是所有的.js文件并把它添加如下:
I had a similar problem. What I did was I copied all the .js files in the same directory as where the html is and added it as follows.
<script type="text/javascript" src="MathJax.js"></script>
我知道这听起来有点傻,但它的工作。
I know it sounds a bit stupid, but it worked.
如果还是不行,请复制js文件到HTML文件本身并尝试像头:
If that doesn't work, copy the .js file into the html file itself and try it like in the header:
<script type="text/javascript">
copy the whole MathJax.js and paste it here
</script>