Mohd Sakib Syed
Mohd Sakib Syed

Reputation: 1769

android how to set hyperlink in textview

I want to set hyperlink with textview in android so anyone can help me on it. My code is given below.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Authentication failed. Please visit www.google.com"
    />

Upvotes: 2

Views: 77

Answers (1)

Panda
Panda

Reputation: 2510

Try this. Add ID field in the xml and then do so.

TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "Authentication Failed . Please visit <a href='http://.www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));

Upvotes: 1

Related Questions