Android没有拿起jQuery Mobile

时间:2014-03-19 06:21:55

标签: android jquery-mobile android-webview

我正在加载一个使用html5和jQuery mobile的简单html文件,该页面在PC浏览器上工作正常,但当我把它放在我的Android应用程序的资源文件夹中并加载到WebView jQuery移动标签时不起作用,例如数据角色,弹出窗口等。

这是我的Android活动代码

WebView index = (WebView) findViewById(R.id.webView1);
index.loadUrl("file:///android_asset/index.html");

这里是html页面的头标记

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="js\jquery.mobile-1.4.2\jquery.mobile-1.4.2.min.css">
<script src="js\jquery.mobile-1.4.2\jquery.mobile-1.4.2.js"></script>
<script src="js\jquery.mobile-1.4.2\jquery.js"></script>
<script src="js\jquery.mobile-1.4.2\jquery.mobile-1.4.2.min.js"></script>
</head>

资产文件夹根目录中的Html文件和jQuery Mobile文件位于assets/jquery.mobile-1.4.2文件夹

2 个答案:

答案 0 :(得分:1)

如果您在JellyBean +设备上运行,则需要输入以下行:

WebSettings s = mWebView.getSettings();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
        s.setAllowUniversalAccessFromFileURLs(true);
        s.setAllowFileAccessFromFileURLs(true);
    }

允许从您的文件访问资产。

答案 1 :(得分:0)

AS Ricky在评论中提出了解决方案,我需要在活动页面上启用javascript,以便通过添加此行来解决问题

WebSettings webSettings = index.getSettings(); webSettings.setJavaScriptEnabled(true);