最佳答案
我想在我的 Android 应用程序中同步调用一些 Java 代码。
I am using this solution: https://stackoverflow.com/a/3338656
我的 Java 代码:
final class MyWebChromeClient extends WebChromeClient {
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d("LogTag", message);
result.confirm();
return true;
}
}
我的 JavaScript 代码:
<html>
<script>
function java_request(){
alert('test');
}
</script>
<body>
<h2>Welcome</h2>
<div id="area"></div>
<form>
<input type="button" value="java_call" onclick="java_request()">
</form>
</body>
</html>
When I tap on the java_call
button, the button goes to the pressed state. I can see 'test'
in the console log. Everything is normal until here.
The problem is, the button never gets back to its normal state. It stays in the pressed state. Maybe the JavaScript execution is broken or something?
为什么按钮永远不会恢复到正常状态?