我想获取在Webview中单击的图像链接,以便在新意图中显示它。我想要图像的网站在点击时不会全屏打开图像。 我想要下面的代码,但网站不会在同一个标签中打开图像。
参考代码:
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url == null){
return false;
}else if (url.trim().toLowerCase().endsWith(".img")) {//use whatever image formats you are looking for here.
String imageUrl = url;//here is your image url, do what you want with it
}else{
view.loadUrl(url);
}
}
}
答案 0 :(得分:1)
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url == null){
return false;
}else if (url.trim().toLowerCase().endsWith(".img")) {//use whatever
image formats you are looking for here.
String imageUrl = url;//here is your image url, do what you want with
it
Intent intent = new Intent(this, NewActivity.class);
//pass from here the data to next activity and load there
intent.putExtra("yourURL", imageUrl);
startActivity(intent)
}else{
view.loadUrl(url);
}
}
}