Android TextView Hyperlink

前端 未结 8 741
悲&欢浪女
悲&欢浪女 2021-02-05 03:45

I\'m implementing a TextView with a string containing two hyperlinks as below but the links are not opening a new browser window:



        
相关标签:
8条回答
  • 2021-02-05 04:11

    Have a look on below code snippet, hope it helps,

    TextView textView =(TextView)findViewById(R.id.textView);
    textView.setClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    String text = "<a href='http://www.google.com'> Google </a>";
    textView.setText(Html.fromHtml(text));
    
    0 讨论(0)
  • 2021-02-05 04:15

    I would recommend you to have two TextViews since ou want two different actions:

    TextView yourTermsOfUseTextView = (TextView) findViewById(R.id.your_id);
    yourTermsOfUseTextView.setOnclickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(your_download_link));
                        startActivity(myIntent);
                    }
                });
    

    Repeat to the privacy policy.

    0 讨论(0)
提交回复
热议问题