/ / ऑटोलिंक एंड्रॉइड में एक टेक्स्ट व्यू के अंदर - एंड्रॉइड, एंड्रॉइड-टेक्स्टव्यू, ऑटोलिंक

एंड्रॉइड में एक टेक्स्ट व्यू के अंदर ऑटोलिंक - एंड्रॉइड, एंड्रॉइड-टेक्स्टव्यू, ऑटोलिंक

टेक्स्टव्यू के कुछ भाग के लिए ऑटोलिंक कैसे दें? उदाहरण के लिए: TextView के अंदर मेरा पाठ है "कृपया इस वेबपेज को खोलने के लिए यहां क्लिक करें"। मैं केवल "यहां" पाठ के लिए लिंक दिखाना चाहता हूं। और मुझे उस वेबपेज को "यहां" पाठ पर क्लिक करना चाहिए, लेकिन टेक्स्टव्यू के कहीं भी नहीं। क्रिप्या मेरि सहायता करे।

उत्तर:

जवाब के लिए 32 № 1

String.xml में एक स्ट्रिंग डालें

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="txtCredits">Support: <a href="http://www.stackoverflow.com">click here</a></string>
</resources>

और आप इसे textView में इस तरह से उपयोग कर सकते हैं:

<TextView
android:layout_width="fill_parent"
android:id="@+id/text"
android:layout_height="wrap_content"
android:autoLink="web"
android:gravity="center"
android:linksClickable="true"
android:text="@string/txtCredits" />

संपादित करें

किसी कारण से ऊपर कोड ठीक से काम नहीं करता है। तो, नीचे कोड भी जोड़ें,

TextView t2 = (TextView) findViewById(R.id.text);
t2.setMovementMethod(LinkMovementMethod.getInstance());

उत्तर के लिए 7 № 2

टेक्स्ट HTML प्रदर्शित करने में सक्षम हैं, जो आपकी समस्या को हल करता है। एक हाइपरलिंक में जो आप क्लिक करने योग्य चाहते हैं उसे लपेटें:

String html = "My link is <a href="http://google.com">here</a>";
myTextView.setText(Html.fromHtml(html));

उत्तर № 3 के लिए 1

HTML सिंटैक्स का उपयोग strings.xml में करें:

<string name="test">Click &lt;a href="http://vtuhtan.info"&gt;here&lt;/a&gt;</string>

क्लिक करने योग्य और ऑटो लिंक करने के लिए TextView गुण सेट करें।

TextView tv = findViewById(R.id.textView);
tv.setText(Html.fromHtml(getResources().getString(R.string.test)));

उत्तर के लिए 1 № 4

आप निम्न कोड के साथ इसका परीक्षण कर सकते हैं:

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

उत्तर के लिए 1 № 5

स्ट्रिंग्स.xml में सरल यूआरएल का उपयोग करें:

<string name="autolink_val">Please Click Here : http://www.google.com</string>

और जावा कोड में यह लिखें:

<TextView android:id="@+id/linkVal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="@string/autolink_val1"/>`