2012-01-24 23 views
8

पर एक वेब लिंक जोड़ना मैं जानना चाहता हूं कि टेक्स्टव्यू विजेट में वेब लिंक जोड़ने के लिए और कैसे संभव है। मेरे ऐप में, मैं कुछ पाठ दिखाता हूं और इस पाठ के आस-पास एक छवि दिखाता हूं। मैं पाठ में एक क्लिक करने योग्य इंटरनेट लिंक डालना चाहता हूं। क्या यह संभव है?टेक्स्ट व्यू विजेट

+1

http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable – VicVu

उत्तर

10

आपको बस एंड्रॉइड सेट करने की आवश्यकता है: संपत्ति को ऑटोलिंक करें।

<TextView 
     android:autoLink="web" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"   
     android:text="http://www.google.com" /> 
+0

Thx, यह पूरी तरह से काम करता है! –

+0

बहुत सीधे आगे और जोड़ने के लिए आसान है। धन्यवाद! +1 – Darrell

0

यह वह जगह है मैं यह कैसे कोड द्वारा किया

private void setAsLink(TextView view, String url){ 
     Pattern pattern = Pattern.compile(url); 
     Linkify.addLinks(view, pattern, "http://"); 
     view.setText(Html.fromHtml("<a href='http://"+url+"'>http://"+url+"</a>")); 
    } 
0

मामले में अपने वेब लिंक पाठ आप TextView में दिखा रहे हैं से अलग है:

अपने लेआउट फ़ाइल में TextView:

<TextView 
    android:id="@+id/textview_with_hidden_clickable_link" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/string_with_text_and_link"/> 

अपने संसाधन फ़ाइल में आपका स्ट्रिंग:

<string name="string_with_text_and_link"> 
    <a href="http://any_web_site">The text in your TextView</a> 
</string> 

और अपने जावा वर्ग में:

((TextView)findViewById(R.id.textview_with_hidden_clickable_link)) 
    .setMovementMethod(LinkMovementMethod.getInstance()); 

नोट: स्ट्रिंग संसाधन में http:// आवश्यक है।

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