如何使TextView中的連接可點擊? - How to make links in a TextView clickable?

問題:

I have the following TextView defined: 我定義瞭如下TextView: android

<TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="@string/txtCredits"
    android:autoLink="web" android:id="@+id/infoTxtCredits"
    android:layout_centerInParent="true"
    android:linksClickable="true"></TextView>

where @string/txtCredits is a string resource that contains <a href="some site">Link text</a> . 其中@string/txtCredits是包含<a href="some site">Link text</a> @string/txtCredits <a href="some site">Link text</a>的字符串資源。 web

Android is highlighting the links in the TextView, but they do not respond to clicks. Android會突出顯示TextView中的連接,但它們不會響應點擊。 Can someone tell me what I'm doing wrong? 有人能夠告訴我我在作什麼錯嗎? Do I have to set an onClickListener for the TextView in my activity for something as simple as this? 我是否須要爲個人活動中的TextView設置onClickListener,就像這樣簡單? this

Looks like it has to do with the way I define my string resource. 看起來它與我定義字符串資源的方式有關。 This does not work: 這不起做用: google

<string name="txtCredits"><a href="http://www.google.com">Google</a></string>

But this does: 但這確實是: spa

<string name="txtCredits">www.google.com</string>

Which is a bummer because I would much rather show a text link than show the full URL. 這真是使人討厭,由於我寧願顯示文本連接而不顯示完整的URL。 .net


解決方案:

參考一: https://stackoom.com/question/BTJ8/如何使TextView中的連接可點擊
參考二: https://oldbug.net/q/BTJ8/How-to-make-links-in-a-TextView-clickable
相關文章
相關標籤/搜索