¿Cómo hacer clic en una parte del texto como un botón en Android?

I would like to add button myButton to TextView. How to get it in a single line so that it looks like one set of lines. Here is sample of the text to be added

Please press this here to refresh the set of values.

I want to have "here" as clickable button. How can I do it. Any snippet on it would be helpful.

preguntado el 31 de enero de 12 a las 08:01

You can try some of these approaches: stackoverflow.com/questions/1697084/… -

5 Respuestas

Set background of Button as null by android:background="@null" give the same text color as given to other TextViewes

or You can take 3 TextView's and setOnClickListener to middle one.

Respondido el 31 de enero de 12 a las 12:01

how to have three textviews followed by one another in a multi line - Karthik

Hey ur suggestion was very useful to me...thanx - user1387035

Simple and Elegant! I needed the link text color to be same as default color of hyperlinks in web. So I put RGB(0, 122, 255), and looks the same! (Y) - Randika Vishman

Set style of Button with borderless android attribut to remove background and border:

    android:text="here" />

Respondido el 16 de junio de 16 a las 11:06

make three textView ex: textView1, textView2 and textView3.

<RelativeLayout android:id="@+id/textLay"
    android:layout_width="fill_parent" android:layout_height="wrap_content"

    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
        android:text="Please press this"/>

    <TextView android:id="@+id/textView2" android:layout_width="wrap_content"
        android:layout_toRightOf="@+id/textView1"  />

    <TextView android:id="@+id/textView3" android:layout_width="wrap_content"
         android:text="to refresh the set of values." 
        android:layout_toRightOf="@+id/textView2"  />


Respondido el 31 de enero de 12 a las 12:01

This doesnt comes well when we take into multi line text.How to solve it in due with modifying the snippet. - Karthik

Just add below attribute to TextView in XML layout file to make it clickable.


In your Java file add OnClickListener to complete click action on text view.

Respondido el 31 de enero de 12 a las 13:01

Añadir android:clickable="true" y android:onClick="yourclickname" para TextView in the XML. Then define yourclickname in your activity. This should make your TextView clickable and triggers the specified method when clicked.

Respondido el 22 de diciembre de 15 a las 08:12

easiest solution and answers the original question exactly. - Jason K.

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.