在TextView中具有HyperLink文本 [英] Have HyperLink Text in TextView

查看:96
本文介绍了在TextView中具有HyperLink文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 TextView 中以超文本形式显示以下文本:

I want to have few text as hyperlink in my TextView like the following image:

此外,类似于上图,我希望超链接打开相应的设置窗口.这怎么可能?

Also, similar to above Image I want the hyperlink to open the respective setting window. How is this possible?

只是为了让我的问题更具体,我想在单击这些文本时打开移动电话设置.因此,我不知道在String对象中使用href标记的URL是什么.

Just to make my question more specific, I want to open cellular setting when those text are clicked. So, I don't know what will be the URL for that to use href tag in String object.

预先感谢!

推荐答案

为此使用 SpannableString

    SpannableString ss = new SpannableString("Your string value");
    ClickableSpan clickableTerms = new ClickableSpan() {
      @Override
      public void onClick(View textView) {
               // show toast here
         }
      @Override
      public void updateDrawState(TextPaint ds) {
           super.updateDrawState(ds);
           ds.setUnderlineText(true);

                }
            };
  ss.setSpan(clickableTerms, 4, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  myTextView.setText(ss);
  myTextView.setMovementMethod(LinkMovementMethod.getInstance());
  myTextView.setHighlightColor(Color.TRANSPARENT);

您可以通过此方法使多个单词可点击.

You can make multiple words clickable by this method.

这篇关于在TextView中具有HyperLink文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆