自动链接里面一个TextView android系统里面、链接、系统、TextView

2023-09-05 08:47:43 作者:冷面枪王

如何让自动链接的TextView中的某些部分?例如:我的内部的TextView文本是请点击此处打开此网页。我想说明的链接仅文本在这里。我应该打开文本在这里,而不是在TextView中的任何地方该网页的onclick。请帮我。

How to give autolink for some part of textview ? For example : My text inside TextView is "Please click here to open this webpage". I want to show link for only the text "here". And I should open that webpage onclick of the text "here" but not on the anywhere of TextView. Please help me.

推荐答案

将一个字符串中string.xml

Put a String in string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="txtCredits">Support: <a href="http://www.stackoverflow.com">click here</a></string>
</resources>

和您可以使用它在TextView中是这样的:

And you can use it in textView like this:

<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:gravity="center"
        android:linksClickable="true"
        android:text="@string/txtCredits" />