这是我的主要 Activity
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>
下面是我的项目图片
在2.3.3,2.2,4.1.2,4.2.2最新版本编译这段代码时
我从源得到正确的输出
但是当我在 3.0,3.1 和 4.0.3,4.0.4 android 版本中编译相同的源代码时
我得到这样的错误输出
friend 请帮助我...我无法解决这个错误...我认为可能是javascript问题。希望你们给我一些想法
我在本地存储 mathjax .. 在 Assets 中
提前致谢...
最佳答案
我遇到了类似的问题。我所做的是将所有 .js 文件复制到与 html 所在的目录相同的目录中,并按如下方式添加。
<script type="text/javascript" src="MathJax.js"></script>
我知道这听起来有点愚蠢,但它确实有效。
如果这不起作用,请将 .js 文件复制到 html 文件本身中,然后像在标题中一样尝试:
<script type="text/javascript">
copy the whole MathJax.js and paste it here
</script>
关于java - Android webview +javascript 未在 android 4.0.x,3.x 中显示输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17376831/