【发布时间】:2022-11-13 22:05:45
【问题描述】:
我正在尝试在我的 TextView 的文本中添加指向网站的链接。
我正在使用 Html.fromHtml() 方法来设置文本,并且链接看起来像预期的那样,但是当我单击它时,它什么也没做。我尝试将 motionMethod 设置为 LinkMovementMethod.getInstance(),但这只是摆脱了我的格式,仍然无法正常工作。
agreementText.text = HtmlCompat.fromHtml("I'm familiar with <a href=\"https://www.sololearn.com/terms-of-use\">terms of use</a> of this website.", HtmlCompat.FROM_HTML_MODE_LEGACY)
agreementText.movementMethod = LinkMovementMethod.getInstance()
我的文本视图:
<TextView
android:id="@+id/agreement_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:linksClickable="true"
android:autoLink="all"/>
【问题讨论】:
标签: android hyperlink textview