Android active link of url in TextView

前端 未结 10 515
盖世英雄少女心
盖世英雄少女心 2020-11-30 22:24

I have getting dynamic text from a web service and showing the same in a TextView. Sometimes the TextView has url like hello

10条回答
  •  隐瞒了意图╮
    2020-11-30 23:10

    Answer is right, BUT not complete, because I had in my xml some properties from other answers like autoLink and linksClickable and programatic way did not work. Also when I passes string with html from string resource also it did not work, so beware, you have to clean your xml and pass string directly exactly as in that answer.

        String text = "click on hello";
        TextView textView = view.findViewById(R.id.textView);
        textView.setText(Html.fromHtml(text));
        textView.setMovementMethod(LinkMovementMethod.getInstance());
    

    I did not try it without without LinkMovementMethod but now I am ok as it finally work. Other answers did not work for me or was for visible url text, not clickable text as link.

提交回复
热议问题