6

I have a textView with one URL.. But I don't want to show the whole URL but only a few words like: Click here. And when the textview is clicked.. The application need to open te URL "behind" the words Click here..

For your information: The textView is clickable now. The URL displays correctly. When the URL is clicked, the browser will start, and load the URL correctly.

I only want to change the text of the link what is visible.

EDIT: Everytime the app restart or reload, the url can be different, so it is nog always the same URL.

KD-21
  • 255
  • 2
  • 6
  • 16

3 Answers3

5

use below code :-

    android:autoLink="web"

like this

<TextView
    android:id="@+id/txt_post_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:autoLink="web"
    android:text=""
    android:textColor="@color/wall_msg"
    android:textSize="16sp" />
duggu
  • 37,851
  • 12
  • 116
  • 113
3

Have you tried using html to achieve this? So for example have the following as your text and then setting

String text = "<a href='www.link.com'>Click here</a>";

textView.setText(Html.fromHtml(text));
riggaroo
  • 2,584
  • 20
  • 34
0

Change the text in your textView to whatever you like. And provide the URL as a variable in your code

EDIT: You say the URL changes: So just save the URL in a variable. Would be interesting how your app receives the new url

PKlumpp
  • 4,913
  • 8
  • 36
  • 64