该Webview中特定链接的Web View onclick事件 [英] Web View onclick event for a specific link in that webview
本文介绍了该Webview中特定链接的Web View onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Web视图,我正在从Web服务在那个wv中调用数据,在Web视图的整个描述中,最后一个链接.所以,我的问题是我想打开该链接的新活动onclick,而不是webview的onclick或webview的ontouch
I have a webview and I am calling data in that wv from a webservice, and in that whole description in a webview, there is a link in the last. so, my problem is that i want to open a new activity onclick of that link only neither onclick of webview nor ontouch of webview
推荐答案
You need to provide an implementation for shouldOverrideUrlLoading
. You'll have to setup a WebViewClient
for your webview and inside of this method, you'll need to have some logic that recognized that link and then open the new Activity
. Something like:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.myWebView);
wv.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(isURLMatching(url)) {
openNextActivity();
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
}
protected boolean isURLMatching(String url) {
// some logic to match the URL would be safe to have here
return true;
}
protected void openNextActivity() {
Intent intent = new Intent(this, MyNextActivity.class);
startActivity(intent);
}
这篇关于该Webview中特定链接的Web View onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文