How to make links in a TextView clickable?

后端 未结 30 3348

I have the following TextView defined:



        
30条回答
  •  Happy的楠姐
    2020-11-21 23:58

    Just wasted so much time to figure out you have to use getText(R.string.whatever) instead of getString(R.string.whatever)...

    Anyways, here is how I got mine working. With multiple hyperlinks in the same text view too.

        TextView termsTextView = (TextView) getActivity().findViewById(R.id.termsTextView);
        termsTextView.append("By registering your account, you agree to our ");
        termsTextView.append(getText(R.string.terms_of_service));
        termsTextView.append(", ");
        termsTextView.append(getText(R.string.fees));
        termsTextView.append(", and the ");
        termsTextView.append(getText(R.string.stripe_connected_account_agreement));
    
        termsTextView.setMovementMethod(LinkMovementMethod.getInstance());
    
    
    
                
    

    string example

        Stripe Connected Account Agreement
    

提交回复
热议问题