How to make links in a TextView clickable?

后端 未结 30 3819

I have the following TextView defined:



        
30条回答
  •  南方客
    南方客 (楼主)
    2020-11-21 23:54

    by using linkify: Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links

    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText("http://www.domain.com");
    Linkify.addLinks(textView, Linkify.WEB_URLS);
    

    Don't forget to

    import android.widget.TextView;
    

提交回复
热议问题