[英]How to make links in textview clickable
How to make links clickable in text view. 如何使链接在文本视图中可单击。 This is the problem 这就是问题
(1). (1)。 view.setMovementMethod(LinkMovementMethod.getInstance());
this works only when textview contains link(anchor tag/href) like this: 仅当textview包含如下链接(锚标记/ href)时,此方法才有效:
<a href="http link">Go to Google</a>
it does'nt work when textview contains link like this: http link 当textview包含以下链接时,它将不起作用:http链接
(2). (2)。 While android:autoLink="web"
this works only when textview contains link like this: http link it does'nt work when textview contains link like this: 当android:autoLink="web"
时,仅当textview包含以下链接时有效:http链接,当textview包含以下链接时不起作用:
<a href="httplink">Go to Google</a>
What to do when textview contains both types of link. 当textview包含两种类型的链接时该怎么办。 Please help. 请帮忙。
try this 尝试这个
<TextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://www.google.com"
android:gravity="center_vertical"
android:textColor="@color/white"
android:textColorLink="@color/white"
android:linksClickable="true"
android:autoLink="web"
android:textStyle="normal"
android:textSize="15sp" />
Try this 尝试这个
textView.setOnClickListener(new View.OnClickListener());
in xml: 在xml中:
android:clickable="true"
or you can use String 或者你可以使用字符串
htmltext=Html.fromHtml(htmltext)
then set this htmltext to textview 然后将此htmltext设置为textview
textview.setText(htmltext)
Try This 尝试这个
String mobile = "12345678";
Set this text with link and click listener 设置带有链接的文本,然后单击侦听器
SpannableString mobile_underline = new SpannableString(mobile);
mobile_underline.setSpan(new UnderlineSpan(), 0, mobile.length(), 0);
textviewID.setOnClickListener(new PhoneNumberClickListener());//Implement custom listener to write respective code of click listener
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.