I am trying to add a URL on my Android App login page which redirects user to recover password.
Asked
Active
Viewed 86 times
0
-
6Possible duplicate of [How do I make links in a TextView clickable?](http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable) – petey Mar 08 '16 at 20:17
-
I'd like to argue that this question is not a duplicate of the question linked above. This question is more about getting users to the password recovery page through interaction, not just making a TextView clickable. I've demonstrated in my answer below what I believe the author is really getting at. – NoChinDeluxe Mar 08 '16 at 20:32
2 Answers
1
I guess you want to show the user a text looking like a url so that when the user taps on it you can redirect him to a web page. In your xml layout, declare a TextView with text attribute set
<TextView android:id = "@+id/txt"
...
android:text= "Click me !">
And in your activity class,
txt = (TextView)findViewById(R.id.txt);
SpannableString content = new SpannableString(txt.getText());
content.setSpan(new UnderlineSpan(), 0, txt.length(), 0);
txt.setText(content);
txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.google.com"));
startActivity(i);
}
});

Shadab Ansari
- 7,022
- 2
- 27
- 45
0
You are thinking in terms of how a web page would do it, but it doesn't necessarily have to be a text link like a web page. You could simply have a button (or any view really) that takes the user to password recovery when touched.
As an example, this is how you would do it with a button in your layout:
Button button = (Button) findViewById(R.id.your_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://www.your-password-recovery-page.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});
This will launch the default browser of the device and navigate to your password recovery url.

NoChinDeluxe
- 3,446
- 1
- 16
- 29
-
Thank you for your help NoChinDeluxe :) but the requirement is strictly a link and not a button. – Ackman Mar 08 '16 at 23:06