mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url)
{
mWebView.loadUrl("javascript:(function(){"+"document.getElementById('portable-banner-main_1').style.display ='none';"+"})()");
}
});
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setBackgroundColor(Color.parseColor("#FFFFFF"));
mWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
mWebView.loadUrl(URL);
我正在隐藏一个元素。但页面有一个加载阶段。所以我需要在onPageFinished之后运行那个javascript函数,就像5秒钟一样。我怎么能这样做?
答案 0 :(得分:3)
使用处理程序。
private static int MY_SLEEP = 5000; // wait 5 seconds.
public void onPageFinished(WebView view, String url){
final Handler handler=new Handler();
final Runnable r = new Runnable()
{
public void run()
{
mWebView.loadUrl("javascript:(function(){"+"document.getElementById('portable-banner-main_1').style.display ='none';"+"})()");
}
};
handler.postDelayed(r, MY_SLEEP);
}
});