[英]Android display html string by a TextView link
我想创建一个 android 链接(具有特定名称),在本地 web 浏览器中显示给定的 html 字符串。 我需要使用 TextView 但它似乎不起作用。
这就是我从日志中得到的:
URLSpan:未找到意图的活动,意图 { act=android.intent.action.VIEW dat= 这里是 html 字符串
这是代码:
链接 = "<a href="" + HtmlString + "">" + 链接名称 + "";
TextView 名称 = ((TextView) findViewById(relevent_int));
name.setText(Html.fromHtml(link, Html.FROM_HTML_MODE_LEGACY));
我假设您想浏览一个网站,因此请确保 URL 格式正确为“http://whatever”或“https://whatever”。 这是一个例子:
val urlString = "https://stackoverflow.com"
val link_name = "Stack Overflow"
val link = "This is the link: <a href=\"" + urlString + "\">" + link_name + "</>"
这将浏览到 Stack Overflow。 如果仍然有问题,请检查调试器中的 URL 以确保其格式正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.