如何处理Android TextView的自动链接点击事件?
这是我在TextView中用于自动链接的XML代码。
<TextView
style="@style/statusTextList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColorLink="@color/hyperlinkColor"
android:linksClickable="true"
android:textColor="#ffffff"
android:autoSizeTextType="uniform"
/>
代码效果很好。 TextView中的Web URL自动突出显示并可以单击。但是,在单击超链接中时,它以错误结尾。
从活动上下文的外部调用startActivity()需要flag_activity_new_task标志。这真的是你想要的吗?
注意:recyclerview项目中的文本视图
问题:如何解决此问题?还是如何以编程方式处理超链接点击事件?
Here is my xml code for autolink in textview.
<TextView
style="@style/statusTextList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:textColorLink="@color/hyperlinkColor"
android:linksClickable="true"
android:textColor="#ffffff"
android:autoSizeTextType="uniform"
/>
Code works perfectly fine. Web url in TextView are auto highlighted and able to click. But on clicking in hyperlink it ends with an error.
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Note: TextView is placed inside recyclerview item
Question : How to resolve this issue? or how to handle hyperlink click event programmatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上无法重现您的错误。
您可以在下面使用代码来处理超链接,以编程方式单击事件:
使用XML的完整工作代码:
I can not reproduce your error actually.
You can use code below to handle hyperlink click event programmatically:
Full working code with xml: