0

I have the following TextView defined:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:autoLink="web"
    android:linksClickable="true"
    android:id="@+id/googleplayservices"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="15dp"
    android:fontFamily="@font/inter_medium"
    android:paddingTop="@dimen/_5sdp"
    android:text="@string/Google_Play_Services"
    android:textColor="@color/black"
    android:textSize="@dimen/_12sdp" />

where @string/Google_Play_Services is a string resource that contains <a href="some site">Link text</a>.

Android is highlighting the links in the TextView, but they do not respond to clicks. What am I doing wrong? Do I have to set an onClickListener for the TextView in my activity for something as simple as this?

3 Answers3

0

Yes, You need To create OnClickListener for this TextView.

refrerence I think this helps you.

Hanif Shaikh
  • 500
  • 1
  • 10
0

Try This

layout.xml

<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hyperlink1"
    android:gravity="center"
    android:textAlignment="center"/>

string.xml

<string name="hyperlink2"><a href="https://www.google.com/">Google</a></string>

JavaFile.java

TextView textView = myDialog.findViewById(R.id.textView);
textView.setMovementMethod(LinkMovementMethod.getInstance());//this line redirect to url
Mayur
  • 332
  • 1
  • 8
0

TextView TV = (TextView)findViewById(R.id.mytextview01);

Spannable wordtoSpan = new SpannableString("I know just how to whisper, And I know just how to cry,I know just where to find the answers");

wordtoSpan.setSpan(new ForegroundColorSpan(Color.BLUE), 15, 30, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

TV.setText(wordtoSpan);