在 web 视图而不是默认浏览器中打开链接 [英] Open a link in a webview instead of default browser

查看:23
本文介绍了在 web 视图而不是默认浏览器中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码:

    TextView noteView = (TextView) view.findViewById(R.id.content);
    noteView.setMovementMethod(LinkMovementMethod.getInstance());
    noteView.setText(Html.fromHtml(noteView.getText().toString()));

我需要在 webview 中打开链接,而不是在浏览器中...这可能吗??我该怎么办??

I need to open links in a webview, not in a browser... is this possible?? how can I do??

提前致谢..

推荐答案

是的,你可以做到,WebView 的任务非常简单,你需要声明一个 WebViewClient 对象并覆盖 public boolean shouldOverrideUrlLoading (WebView view, String url) 方法,在那里你可以过滤urls 或提供一些自定义功能.

Yes, you can do that, it's pretty simple task with WebView, you need to declare a WebViewClient object and override the public boolean shouldOverrideUrlLoading (WebView view, String url) method, there you can filter urls or give some customized functionality.

在您的情况下,要留在 WebView 上,您需要在该方法上返回 false.

In your case, to stay on the WebView, you would need to return false on that method.

查看本教程.

问候

您的问题似乎是如何处理 TextView 网址上的点击事件.由于建议在这个问题上,您可以过滤ACTION_VIEW 对包含 Activity 的 WebView 的意图.如果您需要有关意图过滤器的更多指导,请查看此内容.

It seems your question is how to handle the click event on the TextView's url. As it's suggested on this question you can filter the ACTION_VIEW intent on your WebView containing Activity. If you need more guidance about intent-filters, check this out.

这篇关于在 web 视图而不是默认浏览器中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆