[英]android WebView shouldOverrideUrlLoading()
Hi this doesnt work for me: 嗨,这对我不起作用:
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
s="url clicked: "+url;
view.loadDataWithBaseURL(null, s, "text/html", "utf-8", null);
return true;
}
});
I have links in my html, it shows during loading in main activity, 我的html中有链接,它在加载主活动时显示,
but when I click them I get a white blank screen 但是当我单击它们时,我得到了白色的空白屏幕
I want to be able to read what those urls are, in the program, and I assume this url override function is the purpose for this. 我希望能够在程序中读取这些url的内容,并且我认为此url覆盖功能是用于此目的的。
I have tried with loadData() as well. 我也尝试过loadData()。
Thank you 谢谢
You're not passing the new url to the WebView. 您没有将新的URL传递到WebView。 Should be
应该
view.loadDataWithBaseURL(url, null, "text/html", "utf-8", null);
Edit : This also gives me a blank screen because loadDataWithBaseUrl expects you to provide some text or html as the data
parameter yourself. 编辑 :这也给我一个空白的屏幕,因为loadDataWithBaseUrl希望您自己提供一些文本或html作为
data
参数。 Just use 只需使用
view.loadUrl(url);
I didn't write http:// in my links, and wrote only x. 我没有在链接中写http://,而只写了x。 This was the problem, it works now.
这就是问题所在,现在可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.