Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want text view as a clickable link

Tags:

<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.

like image 799
Rameshbabu Avatar asked Jul 26 '13 09:07

Rameshbabu


People also ask

How do I make a text view clickable?

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.

How do I make a clickable text link?

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.

What is a clickable text in a hyperlink?

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).


2 Answers

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> 
like image 179
Shanewaj Avatar answered Oct 09 '22 10:10

Shanewaj


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" />  
like image 22
Mathew1990 Avatar answered Oct 09 '22 11:10

Mathew1990