1

I have link https://google.com . i want that link just change to string "google"

showed in the TextView is "google"

but actually in google have link https://google.com . and possible to clicked

i have xml :

<TextView
android:id="@+id/social"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginTop="350dp"
android:autoLink="web"
android:linksClickable="true"
android:text="in here social"/>

i have java class :

 TextView social = (TextView) findViewById(R.id.social);
 String text = "<a href='https://google.com'> Google </a>";
 social.setText(Html.fromHtml(text));
Edric
  • 24,639
  • 13
  • 81
  • 91
Gu1Ldr4n
  • 45
  • 1
  • 6
  • Possible duplicate of [How do I make links in a TextView clickable?](https://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable) – Style-7 Oct 28 '19 at 11:09

3 Answers3

2

try this:

 TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());

and in the xml this:

<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txtCredits"/>

In the xml remove the autolink if you are calling setMovementMethod().

Hernâni Pereira
  • 312
  • 4
  • 19
2

you can save your url in tag, like this:

social.setTag("https://google.com");

when you want to get url do this:

String url = (String) social.getTag();
Ehsan msz
  • 1,774
  • 2
  • 13
  • 26
0

Alhamdulillah my problem is solved

in your XML :

<TextView
android:id="@+id/social"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginTop="350dp"
android:linksClickable="true"
android:text="@string/social"/>

in Your Values String

<string name="social">in here social</string>

and in your java class

TextView mSocial = (TextView) findViewById(R.id.social);
mSocial.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(https://google.com));
                startActivity(intent);
            }
        });

make your TextView as String "Social" but if TextView clicked can go to google.com

Gu1Ldr4n
  • 45
  • 1
  • 6