If the textview text contains a phone number or a website address, you can call or open the webpage by clicking the phone number or website address. In Android, you have provided us with such attributes and methods for setting, there are three types:
1. Set the autolink attribute of textview: it has the following values: All, web, phone, and email. When there are these types of text values in the text, click it to enter the webpage, call, or e-mail activity. This is the simplest method.
2. Add links directly to text values
(1) For example, in string. in the XML file: <string> <a href = http://www.google.com> http://www.google.com </a> <a href = "Tel: 18600000001"> Tel </a> </string>, set the textview property setmovementmethod (linkmovementmethod. getinstance ());
(2) Use hteml. fromhtml to build text in the code
Code
tv2.setText(
Html.fromHtml("the google url: " +
"<a href=\"http://www.google.com\">http://www.google.com</a><br/>" +
"the telephone: " +
"<a href=\"tel:18603045201\">18603045201</a>)"
));
tv2.setMovementMethod(LinkMovementMethod.getInstance());
3. Use spanablestring to specify a string as the link text
Code
TextView tv3=(TextView)findViewById(R.id.tv3);
SpannableString ss=
new SpannableString("the google url: http://www.google.com 18600000001");
ss.setSpan(new URLSpan("http://www.google.com"),
16, 37, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan("tel:18603045201"),
38, 49, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv3.setText(ss);
tv3.setMovementMethod(LinkMovementMethod.getInstance());