How to place hyperlink to a website on android app?

后端 未结 1 649
無奈伤痛
無奈伤痛 2021-01-12 10:17

I want to place a hyperlink on android app that I am developing.

I tried this:

main.xml



        
相关标签:
1条回答
  • 2021-01-12 11:10

    Use the default Linkify class.

    Here is an Example and the code from the tutorial:

    This is my sample code for you, I think this will solve your problem:

        public class StackOverflowActivity extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            // 1) How to replace link by text like "Click Here to visit Google" and
            // the text is linked with the website url ?
            TextView link = (TextView) findViewById(R.id.textView1);
            String linkText = "Visit the <a href='http://stackoverflow.com'>StackOverflow</a> web page.";
            link.setText(Html.fromHtml(linkText));
            link.setMovementMethod(LinkMovementMethod.getInstance());
            // 2) How to place email address
            TextView email = (TextView) findViewById(R.id.textView2);
            String emailText = "Send email: <a href=\"mailto:person@stackoverflow.com\">Click Me!</a>";
            email.setText(Html.fromHtml(emailText));
            email.setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
    
    0 讨论(0)
提交回复
热议问题