【问题标题】:Handle android TextView's link click处理 android TextView 的链接点击
【发布时间】:2017-02-11 14:16:50
【问题描述】:

所以我有一个 textView,有时我的 textView 包含链接,当前当我单击此链接时,会打开一个带有已下载浏览器列表的意图。现在我想要的是,我想在当前应用程序中打开这个链接,比如在 WebView 中。我怎样才能做到这一点?

我们确实有多个关于同一主题的文章/问题,但我不知道这些文章/问题的真正含义。

像这个https://gist.github.com/ksoichiro/3394338 给了我一个ClassCastException android.text.style.URLSpan cannot be cast to pb.myPackage.LinkUtils$SensibleUrlSpan

或者这个handle textview link click in my android app

是否有任何直接简单的方法来实现这一点?请告诉我。

【问题讨论】:

标签: android android-studio textview


【解决方案1】:

您可以使用 Chrome 自定义选项卡,这在加载网页时比 webview 更快,而且自定义非常简单。

首先包含库:

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

然后在你的Activity当你调用打开浏览器的方法时添加这些java行:

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

有关更多自定义信息,请参阅它的文档:
https://developer.chrome.com/multidevice/android/customtabs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2010-12-14
    • 2016-04-07
    • 2015-04-27
    相关资源
    最近更新 更多