[英]WebView shouldOverrideUrlLoading Android for imageView
I'm using the following code to load an image in a volley NetworkedImageView and it works well. 我正在使用以下代码在凌空的NetworkedImageView中加载图像,并且效果很好。 But I have one issue I can't seem to resolve.
但我有一个我似乎无法解决的问题。 When the user presses the back button from ImageView, I don't want the image also loaded in the WebView
当用户按下ImageView中的“后退”按钮时,我不希望图像也加载到WebView中
When I return back to my WebView activity the image is loaded there as well. 当我返回到WebView活动时,图像也将加载到那里。
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//NEED TO NOT Load URL in Webview
if (url.toLowerCase().contains(".jpg")) {
startImageView(url);
} else {
view.loadUrl(url);
}
return true;
}
});
This calls the following code to start my ImageView Activity 这将调用以下代码来启动我的ImageView Activity
public void startImageView(String url) {
Intent intent = new Intent(this,
ImageViewActivity.class);
intent.setData(Uri.parse(url));
this.startActivity(intent);
}
Short of calling webView.goBack() in onResume, which I think is rather inelegant, but functional. 缺少在onResume中调用webView.goBack()的功能,我认为它不太雅观,但功能强大。 Is there a way to not have the webView also load the image?
有没有办法让webView也不要加载图像?
Figured it out: 弄清楚了:
I had to override the OnPageStarted method of WebViewClient as follows to keep it from loading the image to start with. 我必须按如下方法重写WebViewClient的OnPageStarted方法,以防止它加载图像。
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
if(url.toLowerCase().contains(".jpg")){
view.stopLoading();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.