简体   繁体   English

处理android TextView的链接单击

[英]Handle android TextView's link click

So i have a textView and sometimes my textView contains links, currently when i click in this link an intent with a list of downloaded browsers opens. 所以我有一个textView,有时我的textView包含链接,当前,当我单击此链接时,将打开一个包含下载的浏览器列表的意图。 now what i want is, i wanna open this link inside the current app, say in a WebView. 现在我想要的是,我想在当前应用程序中打开此链接,例如在WebView中。 how can i do this? 我怎样才能做到这一点?

we do have multiple articles/questions on same topic but i have no idea what this articles/questions are really about. 我们确实有多个关于同一主题的文章/问题,但我不知道这些文章/问题的真正含义。

like this one https://gist.github.com/ksoichiro/3394338 gave me an ClassCastException android.text.style.URLSpan cannot be cast to pb.myPackage.LinkUtils$SensibleUrlSpan 像这样的https://gist.github.com/ksoichiro/3394338给了我一个ClassCastException android.text.style.URLSpan cannot be cast to pb.myPackage.LinkUtils$SensibleUrlSpan

or this one handle textview link click in my android app 或这个句柄textview链接单击我的Android应用程序

is there's any straight simple way to achieve this? 有没有直接简单的方法可以实现这一目标? please let me know. 请告诉我。

You could use Chrome Custom Tabs, this is faster than a webview in loading webpages and is pretty simple to customize. 您可以使用Chrome自定义标签,这比加载网页时的Web视图更快,并且自定义非常简单。

First include the Library: 首先包括库:

dependencies {
    ...
    compile 'com.android.support:customtabs:25.1.1'
}

Then in your Activity when you call the method to open a browser add these lines of java: 然后,在您的Activity当您调用打开浏览器的方法时,请添加以下这些Java行:

String url = ¨https://google.com/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent intent = builder.build();
intent.launchUrl(this, Uri.parse(url));

Refer to it's docs for more customization at: 请参阅以下文档以获取更多自定义信息:
https://developer.chrome.com/multidevice/android/customtabs https://developer.chrome.com/multidevice/android/customtabs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM