<TextView android:id="@+id/link" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="Forget password?" android:autoLink="all" android:linksClickable="true" android:textColor="@color/lgreen" android:textStyle="italic" />
Android is highlighting the links in the TextView, but they do not respond to clicks. Can someone tell me how can i do that as a clickable and move to another link. i tried more times by seeing examples. but i can't. Can some one explain me clearly how to change text view as a clickable link.
Just like Buttons and ImageViews we can add onClickListeners to TextViews by simply adding the attribute android:onClick="myMethod" to your TextView XML tag. The other way, TextView tv = (TextView) this.
Select the text or picture that you want to display as a hyperlink. Press Ctrl+K. You can also right-click the text or picture and click Link on the shortcut menu. In the Insert Hyperlink box, type or paste your link in the Address box.
Hyperlinks are clickable words or images that navigate to other web content. They can connect with almost any resource on the web. When clicked, they'll either take you to a web address immediately or, for certain types of files, give you the option to open a document with an app (like Adobe Reader to open a PDF).
All tested and working 100%
below is a complete example
Solution: android:autoLink="web"
Sample Xml:
<TextView android:id="@+id/txtLostpassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:autoLink="email" android:gravity="center" android:padding="20px" android:text="@string/lostpassword" android:textAppearance="?android:attr/textAppearanceSmall" /> <TextView android:id="@+id/txtLostpassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:autoLink="web" android:gravity="center" android:padding="20px" android:text="@string/defaultpassword" android:textAppearance="?android:attr/textAppearanceSmall" />
String in string.xml
<string name="lostpassword">If you lost your password please contact <a href="mailto:[email protected]?Subject=Lost%20Password" target="_top">[email protected]</a></string> <string name="defaultpassword">User Guide <a href="http://www.cleverfinger.com.au/user-guide/">http://www.cleverfinger.com.au/user-guide/</a></string>
You can add click listener to TextView and start websearch:
textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent browser= new Intent(Intent.ACTION_VIEW, Uri.parse(PASTE_YOUR_URL_HERE)); startActivity(browser); } });
and xml looks like:
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/link_string" android:textSize="14dp" android:autoLink="web" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With