Ultra-simple implementation of TextView in a text hyperlink click Open Browser to jump to the Web page

Source: Internet
Author: User

I want to implement a textview in the middle of a small paragraph of text into a hyperlink, click to call the system's default browser, jump to the specified page such a function. Oneself first toss a bit did not fix, and saw a lot of information on the net, many say in code with what spanned, html.fromhtml () and so on to set TextView, make quite complex, and then add Android to TextView in the layout: autolink= "Web", android:linksclickable= "true" what, but various methods I have tried, do not know why, incredibly all is shit! There is no response after the click.

Finally helpless still have to StackOverflow check a bit, the result found positive solution! And it's a lot easier to achieve than most people say! Needless to say, I immediately put the implementation method to the following:

1) First in the Strings.xml file directly in the TextView to display the hyperlink text, such as, the hyperlink with the HTML tag of the wording to the line

<string name= "Signup_agreeterms" > I agree <a href= "http://www.baidu.com/" > All content in User Agreement </a> </string >

2) Then you have to have a textview in the layout, notice, don't add any more autolink, linksclickable attributes, etc.

<textview android:id= "@+id/signup_txt_agreeterms" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "@string/signup_agreeterms"/>

3) In your activity, add the following code

    TextView TextView = (TextView) Findviewbyid (r.id.signup_txt_agreeterms);    Textview.setmovementmethod (Linkmovementmethod.getinstance ());  Actually, that's the key.

This is OK, it is too simple ...


Attached to the reference StackOverflow address: How does I make links in a TextView clickable?

Ultra-simple implementation of TextView in a text hyperlink click Open Browser to jump to the Web page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.