我的JavaScript没有像我预期的那样改变颜色或维度
我正在尝试在Android网络视图中使用JavaScript。我使用了以下代码。我并没有改变颜色或抵消身体的高度我的JavaScript没有像我预期的那样改变颜色或维度,javascript,android,Javascript,Android,我正在尝试在Android网络视图中使用JavaScript。我使用了以下代码。我并没有改变颜色或抵消身体的高度 webview.getSettings().setJavaScriptEnabled(true); webview.addJavascriptInterface(new myJavaScriptInterface(webview), "jsInterface"); webview.loadUrl("file:///android_as
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new myJavaScriptInterface(webview), "jsInterface");
webview.loadUrl("file:///android_asset/sample/contents.html");
//webview.loadData("file:///android_asset/sample",convertStreamToString(inputStream), "text/html", "UTF-8");
webview.loadUrl("javascript:" +
"document.getElementsByTagName('p')[0].style.color='red';" +
"");
wbview.loadUrl("javascript:window.jsInterface.EchoText(document.body.offsetHeight);");
//webview.
}
class myJavaScriptInterface
{
WebView mywebview;
public myJavaScriptInterface(WebView webview)
{
this.mywebview=webview;
}
public void EchoText(String message)
{
Toast.makeText(mywebview.getContext(), message, Toast.LENGTH_SHORT).show();
}
}
我遗漏了什么?我认为这是因为当您使用
webview.loadUrl(“javascript:+…)
语句时,页面未加载(仍在加载)
试试下面的
webview.loadUrl("file:///android_asset/sample/contents.html");
webview.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView webview, String url) {
webview.loadUrl("javascript:" +
"document.getElementsByTagName('p')[0].style.color='red';");
wbview.loadUrl("javascript:" +
"window.jsInterface.EchoText(document.body.offsetHeight);");
}
});