【发布时间】:2016-12-26 13:29:47
【问题描述】:
我正在尝试使用 WebView 为 Android 创建一个 Web 应用程序。我的cenary很简单,我有一个带有按钮的index.html文件:
<button id="connect-button" onclick="connect">Connect</button>
和一个简单的(脚本)元素:
<script>
connect = function () {
alert("Oi");
};
</script>
在 Android 端,我有一个 Activity 可以在 Webview 上加载此文件
WebView web;
web = (WebView) findViewById(R.id.webview01);
//ProgressBar related to the xml
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
progressBar.setMax(100);
web.setWebViewClient(new myWebClient());
web.setWebChromeClient(new MyWebViewClient());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setLoadWithOverviewMode(true);
web.getSettings().setUseWideViewPort(true);
web.loadUrl("file:///android_asset/index.html");
对于 19 级或更高级别的 API,一切正常。但是对于 api 级别 15 到 18 的 webview 无法加载我的简单 javascript 方法“连接”。
我搜索了很多关于 webview 的 api level bellow 19 的问题,但这是一个非常简单的测试。有些人有时会做一些类似于 api 15 的东西?
【问题讨论】:
标签: android webview android-4.0-ice-cream-sandwich