android - TextView 超链接不起作用?

标签 android xml android-layout hyperlink

为什么 TextView 超链接不起作用。

在自定义对话框中使用超链接。

超链接没有出现。

我哪里弄错了。怎么解决啊。给我指导。

XML代码是

<TextView
android:id="@+id/google_Link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dip"
android:textSize="20dip"
android:linksClickable="true"  
android:autoLink="all"
android:textColorLink="#306EFF"
android:text="" />

安卓代码是

TextView googleLink = ( TextView ) layout.findViewById( R.id.google_Link );
googleLink.setClickable(true);
googleLink.setMovementMethod(LinkMovementMethod.getInstance());
googleLink.setText( Html.fromHtml( "<a href=`http://www.google.co.in`>Google</a>" ) );

Android list 代码是

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

提前致谢。

最佳答案

仅替换此链接,它将起作用:

TextView textView=(TextView) findViewById(R.id.link);
textView.setClickable(true);
String linkTxt=getResources().getString(R.string.link);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml( linkTxt));

在 strings.xml 中添加:

<string name="link">&lt;a href=http://www.google.co.in&gt;Google&lt;/a&gt;</string>

关于android - TextView 超链接不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11413372/

相关文章:

java - 垃圾邮件保护 onclick()

android - MessageQueue回调异常: handleReceiveCallback

java - 如何在Java中为带有属性的自包含标签编写xml注释

android - Leanback VerticalGridFragment 移除顶部间距

java - 在不知道类类型的情况下调用对象的方法

java - 从 XMLResourceParser 获取 org.w3c.dom.Document

xml - 使用 Apache Flink 将数据推送到 S3

android - 使用 xml 在 android 中自定义形状

android - 设置 android :layout_column = "1" 时 TableLayout 不跳过第 0 列

android - 如何以编程方式将主题设置为android对话框?