【发布时间】:2011-02-13 14:59:45
【问题描述】:
我定义了以下 TextView:
<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>
其中@string/txtCredits 是包含<a href="some site">Link text</a> 的字符串资源。
Android 正在突出显示 TextView 中的链接,但它们不响应点击。我究竟做错了什么?我是否必须在我的活动中为 TextView 设置一个 onClickListener 来做这么简单的事情?
看起来这与我定义字符串资源的方式有关。
这不起作用:
<string name="txtCredits"><a href="http://www.google.com">Google</a></string>
但这确实:
<string name="txtCredits">www.google.com</string>
这很糟糕,因为我宁愿显示文本链接也不愿显示完整的 URL。
【问题讨论】:
-
android:autoLink="web" 这是需要添加到 xml 的主线,它的工作原理就像魅力。谢谢@Richard
-
google.com">www.google.com</a></string> 使用上面的字符串就可以了,据了解href和锚标签中的字符串必须相同,并且有 .com 或 .* 工作需要检查原因 -
Some text heregoogle.com">Google</a></string> 对于上面的 sn-p 点击 Some text here should not work in my case 我该怎么办? -
android:focusable="true"解决了我的问题
标签: android hyperlink textview clickable