Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a hyperlink in clickable textview? Android Java [duplicate]

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.

like image 208
KD-21 Avatar asked May 20 '14 08:05

KD-21


2 Answers

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" />
like image 133
duggu Avatar answered Sep 19 '22 06:09

duggu


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));
like image 45
riggaroo Avatar answered Sep 21 '22 06:09

riggaroo