Android中的Web视图不显示警报?

Kar*_*thi 7 javascript java android android-webview

我使用Google提供的示例来演示JavaScript和Java之间的双向通信,

参考文献[1]:

http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

功能正常.我能够从Java调用JavaScript函数并从JavaScript回调Java函数.

问题是当我在JavaScript函数中使用它不会出现警报时,但函数内部的功能正常工作.

为什么alert("test")JavaScript函数内部没有出现在Android中.我加载了一个JavaScript web-view.当我在Android中单击按钮时,我调用该函数,但它没有出现.

如果有人知道这个问题,pealse会帮助我.

谢谢

And*_*oid 15

setContentView(R.layout.main);
        WebView webview = (WebView) findViewById(R.id.webview);

        WebSettings webSettings = webview.getSettings();

        webSettings.setJavaScriptEnabled(true);

        webSettings.setBuiltInZoomControls(true);

        webview.requestFocusFromTouch();

        webview.setWebViewClient(new WebViewClient());
        webview.setWebChromeClient(new WebChromeClient());    

     webview.loadUrl("file:///android_asset/test.html");
Run Code Online (Sandbox Code Playgroud)

这段代码工作完美,并向我显示警报框..这是我的
test.html

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("Hello! I am an alert box!");
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" />

</body>
</html>
Run Code Online (Sandbox Code Playgroud)