gpt4 book ai didi

android - 如何在不使用java的情况下在android上的TextView中制作可点击的url链接

转载 作者:太空宇宙 更新时间:2023-11-03 11:34:19 25 4
gpt4 key购买 nike

在这里,我在 Textview 上使用了可点击的 URL,它起作用了。但是如何使用浏览器设置可点击和突出显示的带有打开 URL 的文本。无需使用像 setText(Html.fromHtml("")) 这样的 java 代码,就可以从 Android XML 或 kotlin 中获取。

String value = "<html>Visit Web <a href=\"http://www.domainname.com\">mysite</a> View</html>";
TextView text = (TextView) findViewById(R.id.text);
text.setText(Html.fromHtml(value));
text.setMovementMethod(LinkMovementMethod.getInstance());

最佳答案

enter image description here

<TextView
android:textSize="18sp"
android:autoLink="web"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="http://www.example.com"
tools:ignore="HardcodedText" />

不需要清除布局 ID,也不需要来自 Java 端的代码。它来自 xml

使用自动链接

    • 对于网站 android:autoLink="web"
    • 用于调用 android:autoLink="phone"
    • 对于电子邮件 android:autoLink="email"
    • 对于 map android:autoLink="web"
    • 对于所有 android:autoLink="all"

关于android - 如何在不使用java的情况下在android上的TextView中制作可点击的url链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44838569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com