所以,我很好奇如何使这项工作......我从API中提取,其中一个元素是HTML格式。所以,我认为将这些链接点击是很酷的。但是,其中一些链接并不完整,因为它们直接与我从中获取API数据的网站绑定。
以下是我所拥有的一个例子:
textSummary.setMovementMethod(LinkMovementMethod.getInstance());
textSummary.setText(Html.fromHtml(object.getDescription()));
现在,如果我点击以" http://"开头的链接一切都很好。它为我提供了打开它的浏览器的选项。但是,如果href看起来像这样:
/inxile-entertainment-inc/3010-3966
我显然遇到错误,因为意图没有格式正确的Url。我应该补充的是:
http://www.giantbomb.com
让部分href工作。
有没有办法做到这一点,最终结果是设备启动默认浏览器(或者我的应用程序之外的浏览器)?
谢谢!
编辑:这是一些更多信息。
这是有问题的TextView。从本质上讲,这是基于从API引入的数据填充此片段的片段。
<TextView android:id="@+id/detail_summary"
android:textColor="@color/colorAccent"
android:layout_marginTop="10dp"
android:paddingStart="3dp"
android:paddingEnd="3dp"
android:paddingBottom="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
错误:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/inxile-entertainment-inc/3010-3966 (has extras) }
此链接将为我提供选择打开它的浏览器的选项:
http://www.youtube.com/watch?v=Gd43NYBzHuk
答案 0 :(得分:2)
你可以使用
机器人:自动连结=&#34;网络&#34;
<TextView android:id="@+id/detail_summary"
android:textColor="@color/colorAccent"
android:layout_marginTop="10dp"
android:paddingStart="3dp"
android:paddingEnd="3dp"
android:paddingBottom="3dp"
android:autoLink="web"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
此 TextView 不需要onClickLinstner