Android绑定JavaScript代码到Android代码不工作?
我使用了Android绑定JavaScript代码到Android代码不工作?,javascript,android,string,Javascript,Android,String,我使用了JavaScriptcode来android使用这个,但是我没有得到String值为什么我要面对这个问题,任何人都知道这个问题,请帮助我 这是我的密码 webview = (WebView) findViewById(R.id.webView); webview.getSettings().setJavaScriptEnabled(true); String html = " <input type='button' value=
JavaScript
code来android
使用这个,但是我没有得到String值
为什么我要面对这个问题,任何人都知道这个问题,请帮助我
这是我的密码
webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
String html = " <input type='button' value='Say hello' onClick='showAndroidToast('Hello Android!')' />" +
"<script type='text/javascript'> function showAndroidToast(toast) { Android.showToast(toast); }</script>";
webview.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
webview.addJavascriptInterface(new WebAppInterface(MainActivity.this), "Android");
这一部分似乎不太可行:
'showAndroidToast('Hello Android!')'
您的报价将无法正确关闭。将转义双引号改为外引号:
\"showAndroidToast('Hello Android!')\"
在该教程中,我将看到这一点。
注意:如果您已将targetSdkVersion设置为17或更高,
是否只可能为17或更高?更低的呢versions@NagarjunaReddy这基本上是一个新问题。但是:您可以为API8和更高版本添加javascript接口。但是,它将不使用注释-它将转到普通类
\"showAndroidToast('Hello Android!')\"