【问题标题】:Linkify with TextView与 TextView 链接
【发布时间】:2016-07-02 06:52:32
【问题描述】:

我想将 Linkify 与扩展的 TextView 一起使用,但如果我在覆盖的 setText() 方法中使用 Linkify,则会因为无限循环而失败。

我找到了这样的解决方案,但它并不漂亮:

textView.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(bypass){
                    bypass = false;
                    return;
                }
                bypass = true;
                if(!Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES)){
                    Linkify.addLinks(textView, phoneMatcher, "tel:", null, Linkify.sPhoneNumberTransformFilter);
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

有没有办法在没有这种解决方法的情况下在 TextView 上使用 Linkify?我希望我的扩展 TextView 自动添加链接(如果有)。

【问题讨论】:

    标签: android textview textwatcher linkify


    【解决方案1】:

    找到合适的解决方案,使用

    addLinks(Spannable s, Pattern p, 字符串方案,MatchFilter matchFilter, TransformFilter (transformFilter)

    然后使用

    设置 spannable

    setText(Spannable spannable)

    方法。

    【讨论】:

      猜你喜欢
      • 2011-06-15
      • 2016-12-13
      • 2011-06-29
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多