2016-08-07 13 views
6

मैं एक स्ट्रिंग नीचे के रूप में दो हाइपरलिंक युक्त एक TextView को लागू कर रहा हूँ लेकिन लिंक एक नई ब्राउज़र विंडो खोलने नहीं कर रहे हैं:एंड्रॉयड TextView हाइपरलिंक

<TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:textColor="#ffffff" 
     android:paddingLeft="50dp" 
     android:paddingRight="50dp" 
     android:textSize="14sp" 
     android:clickable="true" 
     android:linksClickable="true" 
     android:textColorLink="@color/colorPrimary" 
     android:autoLink="web" 
     android:text="@string/agree_terms_privacy"/> 

string.xml में

<string name="agree_terms_privacy">By continuing, you agree to our <a href="http://link1/terms">Terms of Use</a> and read the <a href="http://link1/privacy">Privacy Policy</a></string> 
+2

क्या आपने http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable की जांच की है? – user5599807

+0

उत्तर दें http://stackoverflow.com/a/2746708/2435238 – sJy

+0

मैं स्पैन करने योग्य से परिचित होने का सुझाव देता हूं। http://stackoverflow.com/questions/10696986/how-to-set-the-part-of-the-text-view-is-clickable। – piotrpo

उत्तर

4

है एक कोड का टुकड़ा नीचे पर देखो, आशा है कि यह मदद करता है,

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

मैं तुम्हें सिफारिश करेंगे दो TextViews si के लिए nce ou दो अलग-अलग क्रियाएं चाहते हैं:

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); 
       } 
      }); 

गोपनीयता नीति को दोहराएं।

1

यहां कई समाधान हैं जो एकाधिक स्टैक ओवरफ़्लो पोस्ट को देखने के बाद मेरे लिए काम करते हैं। मैं इसे अपने कार्यान्वयन के अनुरूप है: LinkMovementMethod का उपयोग कर के पक्ष में

1.निकालें स्वत: लिंक, और सच

<TextView 
    android:id="@+id/termsOfUse" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:textColor="#ffffff" 
    android:paddingLeft="50dp" 
    android:paddingRight="50dp" 
    android:textSize="14sp" 
    android:clickable="true" 
    android:linksClickable="true" 
    android:textColorLink="@color/colorPrimary" 
    android:text="@string/agree_terms_privacy"/> 

को linksClickable सेट आप android:autoLink="web" संपत्ति का उपयोग करते हैं तो आपके पास होंगे अपने टेक्स्ट व्यू पर setText() पर कॉल करने से पहले textView.setAutoLinkMask(0); के साथ इसे ओवरराइड करने के लिए। यदि आप पसंद करते हैं तो हर्षल के उत्तर की तरह आप अपनी गतिविधि में क्लिक करने योग्य लिंक भी सेट कर सकते हैं, लेकिन मैंने इसे छोड़ दिया क्योंकि आपके पास पहले से ही लेआउट में था। मैंने आपके टेक्स्ट व्यू में एक आईडी भी जोड़ा जिसे termsOfUse कहा जाता है जिसे हम बाद में उपयोग करेंगे।

2.strings.xml में &lt; साथ < बदलें और यूआरएल

इसका कारण यह है कि जब आप स्ट्रिंग संसाधन को पुनः प्राप्त, इसे सही ढंग से एम्बेडेड एचटीएमएल पार्स नहीं होगा दोहरे उद्धरण चिह्नों के हटाने, और किसी कारण से यह डबल कोट्स से बच नहीं आता है। तो बजाय:

<string name="agree_terms_privacy">By continuing, you agree to our <a href="http://link1/terms">Terms of Use</a> and read the <a href="http://link1/privacy">Privacy Policy</a></string> 

आप क्या करना चाहते होगी:

<string name="agree_terms_privacy">By continuing, you agree to our &lt;a href=http://link1/terms>Terms of Use&lt;/a> and read the &lt;a href=http://link1/privacy>Privacy Policy&lt;/a></string> 

3. स्ट्रिंग संसाधन पार्स और हमारे TextView के लिए यह बाध्यकारी

Spanned policy = Html.fromHtml(getString(R.string.agree_terms_privacy)); 
TextView termsOfUse = (TextView)findViewById(R.id.termsOfUse); 
termsOfUse.setText(policy); 
termsOfUse.setMovementMethod(LinkMovementMethod.getInstance()); 

नोट: एपीआई 24 में Html.fromHtml को बहिष्कृत कर दिया गया है (यदि आवश्यक हो तो इसे संभालने के तरीके के बारे में अधिक जानकारी के लिए this post देखें)। हम अपनी स्ट्रिंग से अपेक्षित HTML स्वरूपण प्राप्त करने के लिए इस विधि का उपयोग करते हैं।

0

मुझे

के लिए यह काम अपने TextView में इस जोड़ें: एंड्रॉयड: autoLink = "सभी" एंड्रॉयड: क्लिक करने योग्य = "true"

https://www.youtube.com/watch?v=UnJxyfyDyHU

मैं इस मदद आप की उम्मीद है।

संबंधित मुद्दे