Android active link of url in TextView

前端 未结 10 518
盖世英雄少女心
盖世英雄少女心 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 22:57

    Check out this approach:

    String text = "Visit stackoverflow.com";
    TextView label = new TextView(this);
    label.setText(text);
    Pattern pattern = Pattern.compile("stackoverflow.com");
    Linkify.addLinks(label, pattern, "http://");
    

提交回复
热议问题